JavaScript for judging the regular expression of this url! Comprehensive. It verifies the IP address, domain name (domain), ftp, second-level domain name, file in the domain name, domain name plus port! User name and other information, it seems that the author is also looking for online, I deducted from a project code, is the strongest and most comprehensive url verification method I have ever seen! The URL verification is very frequent.
Copy codeThe Code is as follows:
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}' // URL in IP Format-199.194.52.184
+ '|' // Allow IP addresses and DOMAIN names)
+ '([0-9a-z _!~ * \ '()-] +.) *' // Domain name-www.
+ '([0-9a-z] [0-9a-z-] {0, 61 })? [0-9a-z]. '// second-level domain name
+ '[A-z] {2, 6})' // first level domain-. com or. museum
+ '(: [0-9] {1, 4 })? '// Port-: 80
+ '((/?) | '// A slash 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 2:
Copy codeThe Code is as follows:
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;
}