JavaScript for regex judgment of this url! More comprehensive. Its verification situations include IP, domain name (domain), ftp, secondary domain name, files in the domain name, domain name plus port! Username and other information seem to be found online by the author. What I deducted from a project code is the strongest and most comprehensive URL verification method I have ever seen! It's too fierce, I'll share it with you here, and URL verification is really 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}' // URL in IP form- 199.194.52.184+ '|' // Allow IP and DOMAIN (domain)+ '([0-9a-z_!~*\'()-]+.)*' // Domain name - www.+ '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].' // Secondary 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); //() if ((str_url)) { return (true); } else { return (false); } }
Code 2:
function CheckUrl(str) { var RegUrl = new RegExp(); ("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");// if (!(str)) { return false; } return true; }
Code Three:
function checkUrl(urlString){ if(urlString!=""){ var reg=/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/; if(!(urlString)){ alert("It's not the correct URL, please check it out."); } } }
Below I will share with you a commonly used regular expression for verification URLs
Regular expressions |
(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?
|
---|---|
match | / | /electronics/ |
Missing |
Regular expressions |
^\\{2}[\w-]+\\(([\w-][\w-\s]*[\w-]+[$$]?$)|([\w-][$$]?$))
|
---|---|
match | \\server\service | \\server\my service | \\serv_001\service$ |
Missing | \\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\.\,\?\'\\/\+&%\$#\=~_\-@]*)*$
|
---|---|
match | | https://64.81.85.161/site/?cow=moo's |ftp://user:pass@:123 |
Missing |
Regular expressions |
^([a-zA-Z]\:|\\\\[^\/\\:*?"<>|]+\\[^\/\\:*?"<>|]+)(\\[^\/\\:*?"<>|]+)+(\.[^\/\\:*?"<>|]+)$
|
---|---|
match | c:\ | \\server\shared\ | \\server\shared\ |
Missing | 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\.\,\?\'\\\+&%\$#\=~_\-]+))*$
|
---|---|
match | /dir/?var=moo | https://localhost |ftp://user:pass@:21/file/dir |
Missing | | /dir// |
Regular expressions |
^([a-zA-Z]\:)(\\[^\\/:*?<>"|]*(?<![ ]))*(\.[a-zA-Z]{2,6})$
|
---|---|
match | C:\di___r\fi_sysle.txt | c:\dir\ |
Missing | c:\dir\file? |
Regular expressions |
^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$
|
---|---|
match | | | |
Missing | | | . |
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\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$
|
---|---|
match | :8103 | /?sort=ASC |/#blah |
Missing | | http:// |
Regular expressions |
\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))
|
---|---|
match | /blah_blah | /blah_blah/ | (Something like /blah_blah) | /blah_blah_(wikipedia) | (Something like /blah_blah_(wikipedia)) | /blah_blah. |/blah_blah/. | </blah_blah> | </blah_blah/>| /blah_blah, | /wpstyle/?p=364. | http://?/123 | rdar://1234 | rdar:/1234 | http://userid:password@:8080 |http://userid@ | http://userid@:8080 |http://userid:password@ |
Missing | no_ws. | no_proto_or_ws.com | /relative_resource.php |