문제

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