Javascript regular expression for one capital
I want to make a regular expression for a string that, to be accepted, needs to have the first letter a capital and the other characters are letters. This is what I tri开发者_运维百科ed:
^[A-Z*[a-z]
This doesn't work though.
^[A-Z][a-zA-Z]+$
Is probably what you want. If the other letters can't be uppercase, remove the second A-Z
.
Yes @minitech is correct. Although this only specifies the beginning of the string (edit: @minitech's answer has now corrected this). It would match "Adf dfgdfg 6756 #%^^%&". To match only strings containing a capital letter followed by other letters use:
^[A-Z][a-zA-Z]+$
This will match "Aa" but not "A". If you want to match "A" then replace the "+" with "*".
精彩评论