Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2005
    Location
    UK, London
    Posts
    762

    Form Validation In PHP

    I need to do 2 simple form validation.

    1. Check if there is invalid charaters inside $_POST["username"]; such as % ^ * ( " ! ? ) , . etc...

    2. Check the entered $_POST["password"]; strength and give the strength in %. for e.g. if the entered password is something like abcd1234WoW, give strength as 100% or close.

    How can i do this? Thanks for any help you offer me.

  2. #2
    Join Date
    Mar 2006
    Posts
    965
    If you currently have some codings I could see, I might be able to help you out here.

  3. #3
    Join Date
    Nov 2003
    Posts
    682
    ctype_alnum() and crack_check()

  4. #4
    Quote Originally Posted by latheesan
    1. Check if there is invalid charaters inside $_POST["username"]; such as % ^ * ( " ! ? ) , . etc...
    try something like
    Code:
    if(preg_match("/\W/i", $_POST["username"])) //bad user name
    Quote Originally Posted by latheesan
    2. Check the entered $_POST["password"]; strength and give the strength in %. for e.g. if the entered password is something like abcd1234WoW, give strength as 100% or close.
    the same idea

    Code:
    $strength = 0;
    
    // do we have digits?
    
    if(preg_match("/[\d]+/i", $_POST["password"])) $strength += 33; //add 33%
    
    // do we have different letter case?
    
    if(strtolower($_POST["password"]) != $_POST["password"]) $strength += 33; //add 33%
    
    // do we have other characters in password?
    
    if(preg_match("/[^\w\d]+/i", $_POST["password"])) $strength += 34; //add 34%

    I can be bad about last regexp, you can find correct pattern syntax here

  5. #5
    Join Date
    Sep 2005
    Location
    India
    Posts
    750
    Darsh Web Solutions : Web Design, PHP Development, E-Commerce Solutions

    PHP Tutorials : Tutorials and scripts for beginners

Posting Permissions

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