Question

Need help creating a validation pattern in javascript for a field.

The value entered must be formatted as follows: xxxxxx-NN-x-NNNN

x = letters or numbers; N = numbers only

Pattern must include the dashes '-' at js positions 6,9,11.

Thanks in advance for your help.

Était-ce utile?

La solution

You can use

/^[A-Za-z0-9]{6}-\d{2}-[A-Za-z0-9]-\d{4}$/

Or shorter with the case insensitive flag:

/^[A-Z0-9]{6}-\d{2}-[A-Z0-9]-\d{4}$/i
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top