Javascript REGEX

I need JavaScript REGEX to verify that the string length is 9 characters. Starts with β€œA” or β€œa,” followed by 8 digits.

Axxxxxxxx or Axxxxxxxx

+4
source share
4 answers

/^[aA][0-9]{8}$/ or /^[aA]\d{8}$/

Also make sure x are numbers :)

+12
source

This should do it:

 /^[aA]\d{8}$/ 

or

 /^a\d{8}$/i 
+3
source

This is probably what you want.

/^([aA]\d{8})$/

A log symbol means that the regular expression should start the search at the beginning of the line, and a dollar symbol means that the regular expression should complete the search at the end of the line. When used together, this means that the string should be checked from start to finish.

Square brackets are used to indicate a specific character or range of valid characters. Slash and d mean search for any digit character. In brackets at the end is the static value that applies to the previous test definition. The range of values ​​can be used by specifying the minimum value, immediately followed by a comma, and then the maximum value.

+2
source

Did you mean this?

 /^[aA]\d{8}/ 

or did you mean 9 characters?

 /^[aA]\d{8}/ 

or did you mean A + 8 equal characters?

 /[aA](.)\1{7}/ 
0
source

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


All Articles