...

View Full Version : need a regex for password validation



kummu4help
12-01-2008, 06:26 AM
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

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.....

martialtiger
12-03-2008, 08:37 AM
You can try this



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! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum