Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post

    Website address form validation

    I need some validation to check the format of a website address eg (www.websiteaddress.com) but im having difficulty finding code to do this, can anyone help me or provide some advice? Would really appreciate it.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by PRodgers4284 View Post
    I need some validation to check the format of a website address eg (www.websiteaddress.com) but im having difficulty finding code to do this, can anyone help me or provide some advice? Would really appreciate it.
    what kind of validation? some basic things you can do, using:

    http://www.php.net/manual/en/ref.url.php

    if you use them take care of php version.

    best regards

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I use this on a few of the sites I've made
    PHP Code:
    function validateURL($str)
    {
        if(!
    preg_match("/^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i",$str))
        {
            return 
    false;
        }
    }
    // Usage:
    if(validateURL('http://codingforums.com'))
    {
    echo 
    'The url is valid';
    }
    else
    {
    echo 
    'The url is not valid';

    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Quote Originally Posted by _Aerospace_Eng_ View Post
    I use this on a few of the sites I've made
    PHP Code:
    function validateURL($str)
    {
        if(!
    preg_match("/^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i",$str))
        {
            return 
    false;
        }
    }
    // Usage:
    if(validateURL('http://codingforums.com'))
    {
    echo 
    'The url is valid';
    }
    else
    {
    echo 
    'The url is not valid';

    Thanks for the reply, il give that a go, thanks ago
    Last edited by PRodgers4284; 02-19-2008 at 05:08 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •