tags:

views:

95

answers:

1

I need a basic regular expression for validating a url, such that:

  • Both http:// and http://www. are allowed (and the same thing with https:// and https://www.).
  • All common tld like .com, .net. .org, .cc, .my, etc are allowed.
  • Things like http://site.com/dir/dir2/page.html etc are allowed
  • Only characters allowed in a url are allowed (such as alphanumeric chars, ?_-.& etc)

Basically something which will check if http:// or https:// is contained, and that at least one tld such as .com, .net, .[something] is contained.

Any ideas?

+6  A: 

Use php's filter

There are good examples on this page

Galen