Forum Moderators: coopster

Message Too Old, No Replies

checking valid url

http, www and com validation of url

         

freshfromseo

2:56 am on Feb 26, 2008 (gmt 0)

10+ Year Member



hi everyone,

does anybody knows how to validate inputted url by the user? it should check if the url has http, www and com, that if the user will just input http://example.com it will echo invalid url and if the user will input [example...] with out the .com it will also notify the user that he/she has inputted the invalid url...

actually im using this url checking if(!preg_match('¦^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$¦i',$url))
but it will only check for the http and not with www and com... please help me..tnx

[edited by: dreamcatcher at 7:59 am (utc) on Feb. 26, 2008]
[edit reason] Use example.com, thanks. [/edit]

dreamcatcher

8:03 am on Feb 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi freshfromseo,

You may be able to use the parse_url() [uk.php.net] function.

dc