How i can add user validate through reqular expression ?

Discussion in 'PHP' started by leadgeneration, Jan 12, 2011.

  1. #1
    Any body can tell me how i can add user validation .....to my website
    I mean length , character using regular expression
     
    leadgeneration, Jan 12, 2011 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    For example to validate the username which length has to be 2-64 characters and allowable characters are a-z, 0-9 and _ use this script:

    
    <?php
    if(preg_match("/^[a-z0-9_]{2,64}$/i",$user)){
        echo("Valid user");
    }else{
        echo("Invalid user");
    }
    ?>
    
    PHP:
     
    s_ruben, Jan 12, 2011 IP