Regex for exactly 6 char, first must be a letter

What is the regex that matches these examples(6 characters, first is a letter, others are numbers):

u78945 - valid
s56123 - valid
456a12 - invalid
78561d - invalid
1234567 - invalid

i don't know if regular expressions are the same for every programming language. I need it for Regular Expression Validator control using VB ASP.NET.


Use this pattern:

^[a-z][0-9]{5}$

This will match any Latin letter (lower-case unless using case-insensitive matching) followed by 5 decimal digits.

Note: You could use d instead of [0-9] , but read this for an explanation about why they are different.


[a-zA-Z]d{5}

If you are searching explicitly from the beginning of the line use ^

^[a-zA-Z]d{5}

and append $ for the end of the line.


^[a(?i)-z(?i)]d{5}$

The (?i ) code enables the expression to accept any letter without case-sensitivity. The d{5} looks for a sequence of numbers whose length is exactly 5.

链接地址: http://www.djcxy.com/p/87000.html

上一篇: 是否有允许正则表达式的JavaScript的String.indexOf()版本?

下一篇: 正则表达式正好6个字符,首先必须是一个字母