Regex to check if the first character is uppercase
I'm trying to check that the first character of a username is capital, the following can be letters or numbers and at most 20 characters long. Can someone explain why my syntax is wrong?
/^[A-z][a-z0-9_-]{3,19}$/
你的第一个Z不是大写Z.
/^[A-Z][a-z0-9_-]{3,19}$/
Your first character needs to be AZ
, not Az
So
/^[Az][a-z0-9_-]{3,19}$/
Should be
/^[AZ][a-z0-9_-]{3,19}$/
我会这样做:
var firstChar = strToCheck.substring(0, 1);
if (firstChar == firstChar.toUpperCase()) {
// it is capital :D
}
链接地址: http://www.djcxy.com/p/21254.html
上一篇: 如何将上部转换为下部并用破折号替换空格?
下一篇: 正则表达式来检查第一个字符是否大写