I want to validate using regex the user input to see if match the following rules.
Valid input:
2-000000000000
1-234342324342
...
Rules:
- It has to be 13 digit numbers, no string.
- Allow hyphen - come after the first character.
- Allow space before and after the hyphen - character.
Here's what I tried in PHP, but still not correct:
if(preg_match("/[0-9?\-[0-9]/i])) {
echo "matched";
}
preg_match("/^\d ?- ?\d{12}\z/", $string)? Note your string literal is malformed. Also,[0-9?\-[0-9]is a malformed regex that matches a digit,?,-or[chars.iis irrelevant here, there are no letters in the pattern.^\d(?:\h*-\h*)?\d{12}$It has to be 13 digit numbers, no string.- regex works only on strings, also2-000000000000is not even a number in first place