A regular expression for a unique number.

I need a regular expression that validates a unique value. It has a unique 9-digit number in the format 000000000A (where 0 is a digit and A is a letter). Only for letters "V" or "X" for the last line.

I can do this for numbers, but don't know how to change the last line.

^[1-9][0-9]{9}$

Hope someone can help me.

+4
source share
4 answers

You can use a character class [VX], it will correspond to one character from it.

^[1-9][0-9]{8}[VX]$

Or OR, as it should

^[1-9][0-9]{8}(V|X)$

Update:

, i

^[1-9][0-9]{8}[VvXx]$
+2

- ( 0)

\d{9}[VX]
+1

d{9}? /\d{9}(V|X)/ .

var test = "qwerty000000000Xqwerty";

console.log(test.match(/\d{9}(V|X)/));

http://jsfiddle.net/u5gmfjeL/1/ - 830363670V.

/i β†’ /\d{9}(V|X)/i β†’ http://jsfiddle.net/u5gmfjeL/2/

+1

:

^[1-9][0-9]{8}[VX]$

, , . , POSIX (ERE), , :

^[1-9][0-9]{8}(V|X)$

ERE

JavaScript Regex

0
source

Source: https://habr.com/ru/post/1617357/


All Articles