I'm getting into regexes, so I might have more than my fair share of questions.
Firstly, I developed a scenario in my head. I want to see if a user has entered 2 consecutive numbers for their age. If they enter 3 numbers, then it's wrong. If they enter 1 number then it's wrong.
I've developed this regular expression.
Code: Select all
<?
$string = 'Scott is 20 years old.';
echo $string;
echo "<BR><BR>";
if(preg_match("/\d{2}\d/",$string))
{
echo "You have entered an incorrect age.";
} ELSE
{
echo "You have entered a correct age.";
}
?>Edit #2:
Code: Select all
preg_match("/(\d)|(\d{3})/",$string)