The javascript! of the regular expression judgment of this URL More comprehensive. It verifies the situation including IP, domain name (domain), FTP, two-level domain name, domain name files, domain name plus port! User name and so on, looks like the author is also on the Internet, I deducted from a project code, is the strongest I have ever seen the most comprehensive way to verify the URL! Too fierce, posted here to share with you, URL verification is very frequent.
function Isurl (str_url) {
var Strregex = ' ^ (HTTPS|HTTP|FTP|RTSP|MMS)?:/ /)'
+ '? ([0-9a-z_!~*\ ' (). &=+$%-]+:)? [0-9a-z_!~*\ ' (). &=+$%-]+@)? ' FTP user@
+ ' (([0-9]{1,3}.) {3} [0-9] {1,3} '//IP form of URL-199.194.52.184
+ ' | '//Allow IP and domain (domains)
+ ' ([0-9a-z_!~*\ ' ()-]+.) * '//Domain name-www.
+ ' ([0-9a-z][0-9a-z-]{0,61}]? [0-9a-z]. ' Level two domain
+ ' [a-z]{2,6}] '//domain-. com or. Museum + '
(: [0-9]{1,4})? '//Port-:
+ ' ((/?) | '//A S Lash isn ' t required if there is no file name
+ ' (/[0-9a-z_!~*\ ' ().;?: @&=+$,%#-]+) +/?) $';
var re=new RegExp (Strregex);
Re.test ()
if (Re.test (Str_url)) {return
(true);
} else {return
(false);
}
Code two:
function Checkurl (str) {
var regurl = new RegExp ();
Regurl.compile ("^[a-za-z]+://[a-za-z0-9-_]+\\.[ a-za-z0-9-_%&\?\/.=]+$ ");//jihua.cnblogs.com
if (! Regurl.test (str)) {return
false;
}
return true;
}
Code Three:
function Checkurl (urlstring) {
if (urlstring!= ") {
var reg=/(Http|ftp|https): \/\/[\w\-_]+ (\.[ \w\-_]+) + ([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
if (!reg.test (urlstring)) {
alert ("Not the right URL, please check it");}}
Here's a regular expression to share a common validation url
Regular expressions |
(HTTP|FTP|HTTPS): \/\/[\w\-_]+ (\.[ \w\-_]+) + ([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?
|
The |
http://regxlib.com/Default.aspx | Http://electronics.cnet.com/electronics/0-6342366-8-8994967-1.html |
does not match |
www.yahoo.com |
Regular expressions |
^\\{2}[\w-]+\\ ([\w-][\w-\s]*[\w-]+[$$]?$) | ( [\w-] [$$]?$))
|
The |
\\server\service | \\server\my Service | \\serv_001\service$ |
does not match |
\\my Server\service | \\server\ Service | \\server$\service |
Regular expressions |
^ (HTTP|HTTPS|FTP) \://([a-za-z0-9\.\-]+ (\:[a-za-z0-9\.&%\$\-]+) *@)? ((25[0-5]|2[0-4][0-9]| [0-1] {1} [0-9] {2}| [1-9] {1} [0-9] {1}| [1-9]) \. (25[0-5]|2[0-4][0-9]| [0-1] {1} [0-9] {2}| [1-9] {1} [0-9] {1}| [1-9]|0) \. (25[0-5]|2[0-4][0-9]| [0-1] {1} [0-9] {2}| [1-9] {1} [0-9] {1}| [1-9]|0) \. (25[0-5]|2[0-4][0-9]| [0-1] {1} [0-9] {2}| [1-9] {1} [0-9] {1}| [0-9]) | ([a-za-z0-9\-]+\.) *[a-za-z0-9\-]+\. [A-za-z] {2,4}) (\:[0-9]+)? (/[^/][a-za-z0-9\.\,\?\ ' \\/\+&%\$#\=~_\-@]*) *$
|
The |
http://www.sysrage.net | Https://64.81.85.161/site/file.php?cow=moo ' s |ftp://user:pass@host.com:123 |
does not match |
Sysrage.net |
Regular expressions |
^ ([a-za-z]\:|\\\\[^\/\\:*?) <>|] +\\[^\/\\:*?" <>|] +)(\\[^\/\\:*?" <>|] +)+(\. [^\/\\:*?" <>|] +)$
|
The |
C:\Test.txt | \\server\shared\Test.txt | \\server\shared\Test.t |
does not match |
C:\Test | \\server\shared | \\server\shared\Test.? |
Regular expressions |
^ (HTTP|HTTPS|FTP) \://([a-za-z0-9\.\-]+ (\:[a-za-z0-9\.&%\$\-]+) *@) * (25[0-5]|2[0-4][0-9]|[ 0-1]{1}[0-9]{2}| [1-9] {1} [0-9] {1}| [1-9]) \. (25[0-5]|2[0-4][0-9]| [0-1] {1} [0-9] {2}| [1-9] {1} [0-9] {1}| [1-9]|0) \. (25[0-5]|2[0-4][0-9]| [0-1] {1} [0-9] {2}| [1-9] {1} [0-9] {1}| [1-9]|0) \. (25[0-5]|2[0-4][0-9]| [0-1] {1} [0-9] {2}| [1-9] {1} [0-9] {1}| [0-9]) | Localhost| ([a-za-z0-9\-]+\.) *[a-za-z0-9\-]+\. (com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum| [A-za-z] {2})) (\:[0-9]+) * (/($|[ A-za-z0-9\.\,\?\ ' \\\+&%\$#\=~_\-]+) *$
|
The |
Http://site.com/dir/file.php?var=moo | Https://localhost |ftp://user:pass@site.com:21/file/dir |
does not match |
site.com | http://site.com/dir// |
Regular expressions |
^ ([a-za-z]\:) (\\[^\\/:*?<> "|] * (? <! [ ]))*(\. [A-za-z] {2,6}) $
|
The |
C:\di___r\fi_sysle.txt | C:\dir\filename.txt |
does not match |
C:\dir\file?name.txt |
Regular expressions |
^ ([a-za-z0-9] ([a-za-z0-9\-]{0,61}[a-za-z0-9]) +[a-za-z]{2,6}$
|
The |
regexlib.com | This.is.a.museum | 3com.com |
does not match |
notadomain-.com | HELLOWORLD.C |. oops.org |
Regular expressions |
^ ((HT|F) TP (s?)) \://)? (www.| [A-za-z].) [A-za-z0-9\-\.] +\. (Com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk) (\:[0-9]+) * (/($|[ A-za-z0-9\.\,\;\?\ ' \\\+&%\$#\=~_\-]+) *$
|
The |
www.blah.com:8103 | Www.blah.com/blah.asp?sort=ASC |www.blah.com/blah.htm#blah |
does not match |
Www.state.ga | http://www.jb51.ru |
regular expression |
\b ([\w-]+://?| www[.]) [^\s () <>]+ (?: \ ([\w\d]+\) | ([^[:p unct:]\s]|/))
|
match |
Http://jb51.net/blah_blah | http://jb51.net/blah_blah/| (Something like Http://jb51.net/blah_blah) | Http://jb51.net/blah_blah_ (wikipedia) | (Something like http://jb51.net/blah_blah_ (wikipedia)) | Http://jb51.net/blah_blah. |http://jb51.net/blah_blah/. | |
|
no_ws.example.com | no_proto_or_ws.com |/relative_resource.php |