Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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}$/
like image 999
Sam Avatar asked Nov 25 '11 21:11

Sam


2 Answers

Your first Z is not a capital Z.

/^[A-Z][a-z0-9_-]{3,19}$/
like image 170
BoltClock Avatar answered Sep 21 '22 05:09

BoltClock


Why can't you let the poor users pick their own usernames? What you should do is convert all caps to lowercase.

"User Name".toLowerCase();

But if you are truly evil, you should change that z to a Z:

/^[A-Z][A-Za-z0-9_-]{3,19}$/
like image 24
Mateen Ulhaq Avatar answered Sep 18 '22 05:09

Mateen Ulhaq