mercredi 11 juillet 2018

Laravel - validate only digits with fixed length and required space

I am writing a regular expression to validate a zip code, where it should have exactly a length of 6 characters, the first 3 characters are digits, the last 2 also, but the character 4 should be a space.
Here some examples:

  • "123456" is not valid because no space in character 4.
  • "123 45" is valid.
  • "123 4" is not valid because the length is 5 instead of 6.

    Here what I wrote:

    /^[0-9 ]{6,6}$/

It works fine, just in this code above, the space is not required (but it should be).



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire