I have searched a lot but didn't get the answer.
How to validate URLs like www.google.com and http://www.google.com
using regular expressions?
Thanks in advance.
2 Answers
You can use a function to test valid url as:
function validateUrl() // return true or false.
{
var urlregex = new RegExp(
"^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)");
return urlregex.test(textval);
}
2 Comments
Jitendra Pancholi
your solution not working at all. see this fiddle jsfiddle.net/KJW4E/1284
Umesh Sehta
jsfiddle.net/KJW4E/1286 this also not working... returning false
You can also use this one, that does not depend on the string start/end:
(\b((?:https?|ftp):\/\/|www\.)([0-9A-Za-z]+\.?)+\b)
See example here.
^(?:http|www). Have you tried anything?