[color=red]自己写的留着自己用的 如果能看懂这个正则的写法的话就可以直接用了[/color]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="JavaScript">
function IsURL(str_url){
alert(str_url);
str_url=str_url.toLowerCase();
var strRegex = "^([\w\u4E00-\u9FA5\uF900-\uFA2D])*"+"<(S*?)[^>]*>.*?|<.*? />"+"[a-zA-Z]*((http)?://)"
+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?"+ "(([0-9]{1,3}\.){3}[0-9]{1,3}"+ "|"+ "([0-9a-z_!~*'()-]+\.)*"+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\."+"[a-z]{2,6})" + "(:[0-9]{1,4})?"+ "((/?)|"+ "((/?)[\w\u4E00-\u9FA5\uF900-\uFA2D]*(/?))"+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)"+ "<(S*?)[^>]*>.*?|<.*? />$";
var tt = str_url.match(strRegex);
var re=new RegExp(strRegex);
alert("!!!!!!!!!!");
//if(tt != null){
for(int i = 0;i<tt.length;i++){
if (re.test(str_url))
{
alert(tt[i]);
return (true);
}
else
{
alert("NO");
return (false);
}
}
//}
}
function aaa(str_url){
//alert(str_url);
str_url=str_url.toLowerCase();
var strRegex = "^([\w\u4E00-\u9FA5\uF900-\uFA2D])*"+
"<(S*?)[^>]*>.*?|<.*? />"+
"[a-zA-Z]*((https|http|ftp|rtsp|mms)?://)"
+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@
+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
+ "|" // 允许IP和DOMAIN(域名)
+ "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
+ "[a-z]{2,6})" // first level domain- .com or .museum
+ "(:[0-9]{1,4})?" // 端口- :80
+ "((/?)|"
+ "((/?)[\w\u4E00-\u9FA5\uF900-\uFA2D]*(/?))"//中文路径
+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)"
+ "<(S*?)[^>]*>.*?|<.*? />$";
var re=new RegExp(strRegex);
if (re.test(str_url)){
alert(re);
return (true);
}else{
return (false);
}
}
function t(regest){
//var regest = "<img src=http://www.baidu.com>";
regest=regest.toLowerCase();
tep = "^<?[img]+>?$";
var temp = new RegExp(tep);
if(temp.test()){
alert(temp);
return(true);
}else{
//alert("不匹配");
return(false);
}
}
</script>
<body>
测试的串
<hr>
<form action="#" method="post">
测试1:<textarea name="text" value="" cols="100" rows="10" οnmοuseοut="IsURL(this.value)"></textarea><br /><br />
测试2:<textarea name="text" value="" cols="100" rows="10" οnmοuseοut="t(this.value)"></textarea>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="JavaScript">
function IsURL(str_url){
alert(str_url);
str_url=str_url.toLowerCase();
var strRegex = "^([\w\u4E00-\u9FA5\uF900-\uFA2D])*"+"<(S*?)[^>]*>.*?|<.*? />"+"[a-zA-Z]*((http)?://)"
+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?"+ "(([0-9]{1,3}\.){3}[0-9]{1,3}"+ "|"+ "([0-9a-z_!~*'()-]+\.)*"+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\."+"[a-z]{2,6})" + "(:[0-9]{1,4})?"+ "((/?)|"+ "((/?)[\w\u4E00-\u9FA5\uF900-\uFA2D]*(/?))"+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)"+ "<(S*?)[^>]*>.*?|<.*? />$";
var tt = str_url.match(strRegex);
var re=new RegExp(strRegex);
alert("!!!!!!!!!!");
//if(tt != null){
for(int i = 0;i<tt.length;i++){
if (re.test(str_url))
{
alert(tt[i]);
return (true);
}
else
{
alert("NO");
return (false);
}
}
//}
}
function aaa(str_url){
//alert(str_url);
str_url=str_url.toLowerCase();
var strRegex = "^([\w\u4E00-\u9FA5\uF900-\uFA2D])*"+
"<(S*?)[^>]*>.*?|<.*? />"+
"[a-zA-Z]*((https|http|ftp|rtsp|mms)?://)"
+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@
+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
+ "|" // 允许IP和DOMAIN(域名)
+ "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
+ "[a-z]{2,6})" // first level domain- .com or .museum
+ "(:[0-9]{1,4})?" // 端口- :80
+ "((/?)|"
+ "((/?)[\w\u4E00-\u9FA5\uF900-\uFA2D]*(/?))"//中文路径
+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)"
+ "<(S*?)[^>]*>.*?|<.*? />$";
var re=new RegExp(strRegex);
if (re.test(str_url)){
alert(re);
return (true);
}else{
return (false);
}
}
function t(regest){
//var regest = "<img src=http://www.baidu.com>";
regest=regest.toLowerCase();
tep = "^<?[img]+>?$";
var temp = new RegExp(tep);
if(temp.test()){
alert(temp);
return(true);
}else{
//alert("不匹配");
return(false);
}
}
</script>
<body>
测试的串
<hr>
<form action="#" method="post">
测试1:<textarea name="text" value="" cols="100" rows="10" οnmοuseοut="IsURL(this.value)"></textarea><br /><br />
测试2:<textarea name="text" value="" cols="100" rows="10" οnmοuseοut="t(this.value)"></textarea>
</form>
</body>
</html>