PhP - Regular Expressions Help?

Memphis

New member
Hi,

My code looks like this:

$namepattern = '/^((\D[A-Za-z--]).{0,31})$/';
if (!preg_match($namepattern, $firstname)){
$emptyfirstname="errortext";
$flag="NOTOK";
$firstnamealpha = "NOTOK";
}
else if (!preg_match($namepattern, $firstname)){
$emptyfirstname="basictext";
$flag="OK";
}

Then I simply print an error if it does not match the code when the form returns. I have set my regular expressions to accept only letters and hyphens and to be within 1-32 characters. However whenever I put {1,32} it actually turns out that its {2,33}. What I cannot understand now, is that whenever I try and submit the field, the validation returns will not be accepted unless there are two characters present...When I have set it to just one.

Does anyone know why this is?
 
Back
Top