Reputation: 41
I have string like "ABC 1000", "ABC 1", "ABC 100".
In above string example, first 3 character i.e. ABC is fixed every time and then digits, digits can be long upto N numbers.
In 2nd part i.e. after "ABC " it should always be numberic value, no alphabet, no special symbol.
So, how can I manage with regular expression. Please help.
I have tried with following but failed ..
$var="ABC 100";
preg_match("/^INR /[0-9]+/", $var)
Upvotes: 3
Views: 6660
Reputation: 72855
You could use this:
^[A-Za-z]{3} *\d+$
$var="ABC 100";
preg_match("/^[A-Za-z]{3} *\d+$/", $var)
Upvotes: 1
Reputation: 780818
You have an extra /
in your regular expression. It should be:
preg_match('/^ABC \d+/', $var);
Upvotes: 5