I'm a regex noob who is missing some major basic point.
The documentation on ereg() and preg_match() say something to the effect that, if the regex finds a match in a string, it returns "true". And yet, when it is used, it appears that it is used to return "false" for expressions that contain extraneous characters even if the string contains a substring that fully matches the regex.
I may just be incorrect. However, the second paradigm is what I think I have noticed.
I coded
if (preg_match(('/^[1-9][0-9]$/'), ($_POST['age']))) {
$age = $_POST['age'];
} else {
die("Age must be an integer between 10 and 99, please re-enter.");
}
This gave me the "die" message for the value "44x44".
Is my code wrong?
Is this just a code misunderstanding, ie, my expression means "has to start and end with the same two-digit substring"?
There is obviously something the size of an elephant I am missing here.
(PS this is not a practical problem, the expression works fine and I only allowed a five-digit return to sturdy the regex -- the actual form has a maxlength of 2 so "44x44" is impossible.