javascript - url validation not working -


i using javascript url validation regular expression. not working in cases.i want urls below,it must work .com,.in .us etc

    http://mysites.com      http://www.mysite.com      https://mysite.com     https://www.mysite.com     ftp://mysite.com     ftp://www.mysite.com     www.mysite.com     mysite.com     usa.mysite.com 

i using regular expression ,

var regex = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\s+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;  

its not working in case of www.mysite.com , mysite.com etc .

any 1 please me.

try regex:

var regex = /^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -