I am trying to create a simple regular expression but i am not getting it. I want a simple regular expression which should check if the user has entred 10 chars. whcih are all numbers.
I tried the following but i don’t understand why it is not working:
if (preg_match ("(?\\b[0-9]{10}\\)\\b", "1234567890")) { echo "match"; } else { echo "no match"; }
if (preg_match ("/^\\d{10}$/", "1234567890")) {
echo "match";
} else {
echo "no match";
}
/ - start regex
^ - match start of string - i.e., don’t match if there is anything before here
\d - match all digit (0-9)
{10} - match exactly 10 times
$ - match end of string - i.e., don’t match if there is anything after here
/ - end of regex