javascript - URL Validation - Accepts URLs without protocols -


I have a basic url validation in my applican right now I am using the following code.

  // is valid whether the value given is valid URL function is valid URL (value) {var regexp = / (ftp | http | https): \ / \ / (\ w +: {0,1} \ W * @) (\ S +) (: [0-9] +)? (\ / | \ / (\ W #: +!!? = & Amp;% @! \ - \ /])) / return regexp.test (value); }  

but it is not accepting the URL without the protocol. If I provide www.google.com for the former, then he is not accepting it. How can I modify this RegEx to make the URL acceptable without the protocol?

There is a long regex for matching a URL:

  (? I) \ b ((?: (?: [Az] [\ w -] + :)? (?: / {1,3} | [A -z0-9%]) | www \ d { 0.3} [] | [One-Z0-9 \ -] [] [az] {2,4} /) (: ...? [^ (S) <>] | \ (([ ^ \ S () <> (<[([^ \ s ()) <<))) *)) (+ (: ([[^ \ s ()) & amp; Lt;>] | (\ [[^ \ s () ]))) * \) | [^ \ s` () \ [\] {}:: ''.,  

An extended version of it (to help understand it):

  (? Xi) \ b (# Capture 1: Completed match URL (?: (?: [Az] [\ w]] + :)? # URL protocol and colon (?: / {1,3} # 1 -3 slash | # or [a-z0-9%] # # Or www \ d {0.3} [.] # "Www.", "Www1.", or "%" for example ("URI :: escape" is not being matched with). "Www2." ... "www999." | # Or [a-z0-9]. [- az] {.] [Az] {2,4} / # appears like a domain name after a slash) (?: # One or more: [^ \ s ()) and; gt; + # part of non-space, non-() ] + | (\ [[^ \ s ()  | + | (\ [[^ \ s ()] <<)] + \))) * \) #Balanced legs, level up to 2 | or [^ \ s`! () \ [\] {} :: '.', " ""] #location or not one of these sections))  

Both of these come, but slightly modified to make the alternative alternate - you should read this page to help understand it That's what it's doing, and there's a version like this. Which only corresponds to the web-based URL, you can see.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -