regex - Regular Expression for email to check repetitive characters -
i'm validating email address regular expression. test following conditions:
minimum of 3 characters in name, symbol @, minimum 3 characters in first part of domain, dot,no more 3 repetitive characters
i tried regular expression , it's working fine cases except last one.
/^[a-za-z0-9._%+-]{3,}\@[a-za-z0-9.-]{3,}\.[a-za-z]{2,4}$/
it's not checking repetitive character(any character) after dot(.)
not ok: test@test.ccccom, test@test.coooom
ok : test@test.com
don't know wrong last portion of re.
any input appreciated.
you can use following regex:
^(?!.*([a-za-z0-9])\1{3})[a-za-z0-9._%+-]{3,}\@[a-za-z0-9-]{3,}\.[a-za-z]{2,4}$
changes made:
(?!.*([a-za-z0-9])\1{3})
- negative lookahead makes sure none of characters repeat more thrice in row.
the rest of regex same is, except removal of .
second character class.
if want disallow repeated characters after last .
, use following instead:
^[a-za-z0-9._%+-]{3,}\@[a-za-z0-9-]{3,}\.(?!([a-za-z0-9])\1{3})[a-za-z]{2,4}$
Comments
Post a Comment