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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need a regex for password validation

    can anyone give me a regex to validate the password with following conditions

    1. password should have atleast one alphabet and atleast one digit.
    2.password should be atleast 6 characters and maximum of 8.
    3. also password can allow specialcharacters but it is not mandatory.
    without spl.characters also password is valid but it should have atleast one alphabet and minimum 1 digit.
    present i am trying the following
    Code:
    function isAlphaNumeric($sInput)
    {
        if(false===(preg_match("/[a-zA-Z]/", $sInput) > 0))
    	{
    		return false;
    	}
    	if(false===(preg_match("/[0-9]/", $sInput) > 0))
    	{
    		return false;
    	}
    	return true;
    }
    hope i am clear.
    i tried with ctype_alnum() function in php but it is accepting if all characters or either alphabet or digit. but i want to enforce atleast one alphabet and one digit should be in password

    can any one give me a regex for this pls.....

  • #2
    New Coder
    Join Date
    Jul 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can try this

    PHP Code:
    function isAlphaNumeric($sInput)
    {
        if(
    preg_match("^(?=.*[0-9]+.*)(?=.*[a-zA-Z]+.*)[0-9a-zA-Z]{6,8}$/"$sInput))
        {
            return 
    true;
        }
        else
        {
            return 
    false;
        }

    Good luck!


  •  

    Posting Permissions

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