开发者

Field should not exceed 4 characters and characters should be unique

I have a textbox where i will be entering values into textbox, my regular expression should validate for

It should allow 4 characters should not exceeding more than that, it sh开发者_开发技巧ould not allow numbers and special characters , and my characters should not be duplicate for example it should allow ABCD , and should not allow AABD or ABCB


How about this?

^(?:([a-z])(?!.*\1)){1,4}$

See it here online on Regexr

I used the modifier i (IgnoreCase). You can add to the character class [a-z] any character you want to allow.

Each character is matched by ([a-z]) stored in the capture group 1. The negative lookahead (?!.*\1)) checks for every character if it is repeated somewhere else in the string.

{1,4} allows from 1 to 4 characters. I am not completely sure about your spec here, if you want to have exactly 4 then change it to {4}

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜