How to remove dot (.) Character in email using regex

I have an email address, for example n.abc@abc-xyz.de

, and I came up with a simple template like:

String reglarEx="^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?\\.)+[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])$"

      

My requirement is to prevent the dot(.)

pre-sign operator @

or the entire email address containing only one dot operator.

+3


source to share


1 answer


You can use this regex:

String reglarEx = "^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+@([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?\\.)+[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])$";

      

Or abbreviated:



String reglarEx = "^[\\w!#$%&'*+/=?^`{|}~-]+@(\\p{Alnum}(\\p{Alnum}*\\p{Alnum})?\\.)+\\p{Alnum}(\\p{Alnum}*\\p{Alnum})$";

      

Although the entire email address only contains one dot operator , it doesn't seem to be correct, as email can also be name@google.co.uk

.

+3


source







All Articles