jeudi 2 mars 2017

Regex quantifier with capturing group issue

whats up?

I'm trying to get some regex to work, but I'm facing some "weird" (?) behaviour.

I need a regex that validates the following:

  • Only numbers (no whitespaces at all)
  • Starts with 10 or 11
  • Max 12 characters

After working for a while on this I'm stuck with this:

^(10|11)[0-9]{10}$

It seems to be working as desired, but I'm not satisfied since it's misleading at first glance. Must be 12 max characters but it validates max 10 + the 'starts with' characters.

Anyone have a better solution or care to explain why this is happening?

Thanks in advance (:

Aucun commentaire:

Enregistrer un commentaire