Regular expression which prevents certain characters and repeated characters
I am trying to validate a user input in my JSF application where the user
(1) should not enter their email address (that simply means the '@' cha开发者_开发技巧racter should not come there)
(2) should not enter their phone number (we may simply reject if the input contains minimum of 4 digit number input)
(3) should not keep on pressing the same button (we may reject if the input contains minimum of 4 repeated characters)
I need a regular expression to do the above validation.
I think here it's easiest to match based on what you can't accept rather than what you can. The regex @|\d{3}\d+|(.)\1{3}
is quite simple and easy to understand, and you can reject any input that that matches it.
You can use negative lookahead assertions for this as:
^(?!.*@)(?!.*\d{4})(?!.*?(.)\1{3}).*$
Rubular link
精彩评论