Web Analytics Made Easy -
StatCounter Regex to check for a valid web address - CodingForum

Announcement

Collapse
No announcement yet.

Regex to check for a valid web address

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Regex to check for a valid web address

    I need to codea regex to check if a user submitted a valid web address but ive no idea how to do it.

    Id guess it needs to match [http(s)://][(a-zA-Z0-9 and - and .)][.(a-z){2+}]

    but i know that wouldnt be the correct syntax for it, but i cant seem to get it right.

    Can anyone help?

  • #2
    Rather than writing a complex expression, check out filter_var():
    http://www.php.net/filter_var
    PHP Code:
    $url 'http://example.com';

    $url_filtered filter_var$urlFILTER_VALIDATE_URL );

    if ( 
    FALSE !== $url_filtered )
    {
        
    // correct URL structure

    ZCE

    Comment


    • #3
      Ahh that looks better than a regex, thanks

      Comment

      Working...
      X