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.

有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top