1

I'm using preg_match to find two letters and 4-6 digits, but there should be a hyphen - character in the middle. I'm starting from there:

if (preg_match("/^[a-zA-Z]{2}\W[0-9]{4,6}$/"...

I came out with this solution, where I use \W as an any "non-word" character. But I know it will be a hyphen, so I would like to be more specific.

if (preg_match("/^[a-zA-Z]{2}.-.[0-9]{4,6}$/"...
syluccy
  • 21
  • 3

2 Answers2

0

It would be enough to replace \W with a fixed character:

if (preg_match("/^[a-z]{2}-\d{4,6}$/i"...
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105
-1

wow, Wiktor Stribiżew's answer was it. I didn't know it was so easy...

so it's

if (preg_match("/^[a-zA-Z]{2}-[0-9]{4,6}$/"...

syluccy
  • 21
  • 3