Reputation: 31
How can I improve my My RegEx in order to forbid input only digits in my email.
My RegEx:
^([a-z0-9а-я_.-]{4,20})@([a-zа-я_]{2,5})\\.([a-zа-я]{2,5})(\\.[a-zа-я]{2,5})?$
Invalid:
[email protected]
Valid:
[email protected]
Upvotes: 2
Views: 787
Reputation: 626950
You may add (?![0-9]+@)
after ^
in your regex:
^(?![0-9]+@)([a-z0-9а-я_.-]{4,20})@([a-zа-я_]{2,5})\\.([a-zа-я]{2,5})(\\.[a-zа-я]{2,5})?$
^^^^^^^^^^^
The negative lookahead will fail all cases where you have 1 or more digits followed with @
at the start of the string.
See the regex demo.
Upvotes: 3