Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

JS verifies what are the regularities of URL functions

Shulou Source: shulou.com Published: 2022-06-02 03:21:40 09月30日 Update

This article is about what JS verifies the regularities of URL functions. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The regular expression of this url determines the JavaScript! It's more comprehensive. It verifies situations including IP, domain name (domain), ftp, second-level domain name, files in domain name, domain name plus port! User name and other information, it seems that the author is also found on the Internet, I deducted from a project code, is the strongest and most comprehensive url verification I have ever seen! Too fierce, posted here to share with you, URL verification is really very frequent.

Function IsURL (str_url) {var strRegex ='^ ((https | http | ftp | rtsp | mms)?: / /)'+'? (([0-9aMuzhuyun) *\'(). & = + $% -] +:)? [0-9aHUZHUZHONG * * (). & = + $% -] + @)?'/ ftp user@ +'(([0-9] {1m 3}.) {3} [0-9] {1m 3}'/ IP form of URL -199.194.52.184 +'|'/ / allow IP and DOMAIN (domain name) +'([0-9a Mushroom domains *\'() -] +.) *'/ domain name-www. +'([0-9a-z] [0-9amurz -] {0jue 61})? [0-9a-z].'/ / second-level domain name +'[amerz] {2jue 6})'/ / first level domain- .com or .museum +'(: [0-9] {1jue 4})?'/ / port -: 80 +'((/?) |'/ / a slash isn't required if there is no file name +'(/ [0) -9a murmur, please pay attention to * (). ?: @ & = + $,% # -] +) /?) $'; var re=new RegExp (strRegex); / / re.test () if (re.test (str_url)) {return (true);} else {return (false);}}

Code 2:

Function CheckUrl (str) {var RegUrl = new RegExp (); RegUrl.compile ("^ [A-Za-z] +: / / [A-Za-z0-9muri _] +\. [A-Za-z0-9murf% &\? /. =] + $"); / / jihua.cnblogs.com if (! RegUrl.test (str)) {return false;} return true;}

Code 3:

Function checkUrl (urlString) {if (urlStringstones = "") {var reg=/ (http | ftp | https):\ /\ / [\ w\-_] + (\ .[\ w\-_] +) + ([\ w\ -\, @? ^ =% &: / ~\ + #] * [\ w\ -\ @? ^ =% & / ~\ + #])? /; if (! reg.test (urlString)) {alert ("it's not the correct URL, please check it") }}}

Let's share with you a common regular expression for verifying a URL.

Regular expression

(http | ftp | https):\ /\ / [\ w\-_] + (\ .[\ w\-_] +) + ([\ w\ -\, @? ^ =% &: / ~\ + #] * [\ w\ -\ @? ^ =% & / ~\ + #])?

Match http://regxlib.com/Default.aspx | http://electronics.cnet.com/electronics/0-6342366-8-8994967-1.html does not match www.yahoo.com regular expression

^\ {2} [\ w -] +\ (([\ w -] [\ w -\ s] * [\ w -] + [$]? $) | ([\ w-] [$]? $)

Match\\ server\ service |\\ server\ my service |\\ serv_001\ service$ does not match\\ my server\ service |\ server\ service |\ server$\ service regular expression

^ (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] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | [1-9] | 0)\. 5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | [a-zA-Z0-9\ -] +\.) * [a-zA-Z0-9\ -] +\. [a-zA-Z] {2 a-zA-Z 4}) (\: [0-9] +)? (/ [^ /] [a-zA-Z0-9\.\) \?\'\\ /\ + &%\ $#\ = ~ _\-@] *) * $

Match 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 expression

^ ([a-zA-Z]\: |\\ [^\ /\\: *? "|] + [^\ /\\: *?" |] +) (\\ [^\ /\: *? "|] +) + (\. [^\ /\: *?" |] +) $

Matches c:\ Test.txt |\\ server\ shared\ Test.txt |\\ server\ shared\ Test.t does not match c:\ Test |\\ server\ shared |\\ server\ shared\ Test.? Regular expression

^ (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] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | [1-9] | 0)\. | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | localhost | ([a-zA-Z0-9\ -] +\.) * [a-zA-Z0-9\ -] +\. (com | edu | gov | int | mil | org | biz | arpa | info | pro | coop | museum | [a-zA-Z] {2})) (\: [0-9] +) * (/ ($| [a-zA-Z0-9\.\) \?\'\\ + &%\ $#\ = ~ _\] +)) * $

Match 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 expression

^ ([a-zA-Z]\:) (\\ [^\\ /: *? "|] * (?

Match C:\ di___r\ fi_sysle.txt | c:\ dir\ filename.txt does not match c:\ dir\ file?name.txt regular expression

^ ([a-zA-Z0-9] ([a-zA-Z0-9\ -] {0rect 61} [a-zA-Z0-9])?\.) + [a-zA-Z] {2jue 6} $

Matches regexlib.com | this.is.a.museum | 3com.com does not match notadomain-.com | helloworld.c | .oops.org regular expression

^ (ht | f) tp (s?))\: / /)? (www. | [a-zA-Z].) [a-zA-Z0-9\ -\.] +. (com | edu | gov | mil | org | biz | name | museum | ca | uk) (\: [0-9] +) (\: [0-9] +) * (/ ($| [a-zA-Z0-9\.\,\;\'\ + &%\ $#\ = ~ _\ -] +) * $

Match 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] +\) | ([^ [: punct:]\ 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/. | | http://jb51.net/blah_blah, | http://www.example.com/wpstyle/?p=364. | | | http://?df.ws/123 | rdar://1234 | rdar:/1234 | http://userid:password@example.com:8080 | http://userid@example.com | http://userid@example.com:8080 | http://userid:password@example.com does not match no_ws.example.com | no_proto_or_ws.com | / relative_resource.php Thank you for reading! This is the end of this article on "what are the regularities of JS verifying URL functions?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Regular expression domain name validation code function second-level domain name content more port article URL good practical most complete strongest most frequent author information commonly used Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Tech Info MariaDB Huawei Linux