PDA

Click to See Complete Forum and Search --> : regex to validate URL[solved]


Techno
May 25th, 2006, 08:58 AM
Hi.
I found a few regex on the net to validate a url however it doesnt quite work for me.

I want to make sure that the url is validate on this condition:

optional 'www' beginning
ends with a . (we do not care about if it ends in co.uk or com as in the future who knows what other domains will be available)

any ideas?

I also want to make sure that something like this is invalid:

spaces in the url
http://.xxxxxx

that dot should not be there...invalid url


the one I am currently using which appears to work reasonably is this one however it does have it's flaws.

^(http|ftp)://(www\.)?.+\.

Techno
May 25th, 2006, 10:27 AM
this one seems to work:

^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$

got it from:
http://regexlib.com

good site for regex!