javascript - validate url without https:// http:// means also can accpet if url is www accpets both (http and www) -
hi trying build regex using javascript url can accepts https:// ( http://) or without http url starts www.
like
http://www.google.com https://www.google.com www.google.com
here regex
/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/|www\.)[a-z0-9]+([\-\.]{1}[a-z0-9]+)+\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/
but wrong here times accpet not accept
www.abc.com
it accpets www.acbc ,
http://www.google https://www.google
kindy me out in advance
try this: ((http|ftp|https)://)?([a-za-z0-9\._-]+\.[a-za-z]{2,6})(:[0-9]{1,4})*(/[a-za-z0-9\&%_\./-~-]*)?
update:
if want use in javascript, should be:
var re = /((http|ftp|https):\/\/)?([a-za-z0-9\._-]+\.[a-za-z]{2,6})(:[0-9]{1,4})*(\/[a-za-z0-9\&%_\.\/-~-]*)?/; console.log(re.test('http://www.google.com')); console.log(re.test('https://www.google.com')); console.log(re.test('www.google.com')); console.log(re.test('google'));
the definition of url board, suppose regular expression can't jobs.
Comments
Post a Comment