Friends!
Help please, you need to realize the next opportunity. It is necessary to give the user only data of a limited format.
The field must have a size of 12 or 14 characters. In this case, it is permissible to enter only 1 alphabetic character, 1 space and the rest of the numbers, while spaces and alphabetic characters may not be, but the size must be exact.
^(([a-zA-Z ]?[0-9]){12}|([a-zA-Z ]?[0-9]){14})$ - this is not suitable.

  • this one doesn't fit. - why not fit? - Grundy
  • because if you do not enter a letter or space, the number of characters will not be 12 and 14 but 13 and 15 - El Salvadore
  • not understood. 13 numbers only - is this a valid combination or not? - Grundy
  • You can enter 12 or 14 digits in total. This particular number does not depend on whether you entered alphabetic characters or a space if you entered 1 letter, then you can enter only 11 digits - El Salvadore
  • Yeah, and then what is the problem with because if you do not enter a letter or space, then the number of characters will not be 12 and 14 but 13 and 15 ? - Grundy

1 answer 1

 /^((?!(.*[az ].*[az ].*))([0-9a-z ]{12})|(?!(.*[az ].*[az ].*))([0-9a-z ]{14}))$/gi 

https://regex101.com/r/NIk0cs/1