i just try like this.
for($i=0;$i<$length;i++)
{
if(!ctype_alpha($password[$i])
{
header("location:regist.php?err=Password not contain letter");
}
else if(!is_numeric($password[$i]))
{
header("location:regist.php?err=Password not contain numbers");
}
else
{
//??
}
}
how to validate password if the password must alphanumeric without using regular expression ?
I think you are looking for ctype_alnum
Check- http://www.php.net/manual/en/function.ctype-alnum.php
UPDATE-
You can check for special characters in your string by something like-
<?php
$test = "password123";
$special_char = "#$%^&*()+=-[]';,./{}|:<>?~";
if (false === strpbrk($test, $special_char))
{
echo "Good Password";
}
?>
( may be this is ugly coding) but this is what you need
$str="123adsd##$";
$error ='string should be alphanumeric';
$str1 = str_replace(range(0,9), '', $str);
$alph = array_merge(range('A', 'Z'), range('a', 'z'));
if(strlen($str1)>strlen($str) || strlen($str1)<strlen($str))
{
$str2 = str_replace($alph, '', $str1);
if(strlen($str2)>strlen($str1) || strlen($str2)<strlen($str1))
{
if(strlen($str2) >0)
{
echo $error;
}
}
else{
echo $error;
}
}
else{
echo $error;
}
output
string should be alphanumeric