开发者

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 "*".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜