简体   繁体   中英

How to remove dot (.) character in email address using regular Expression

I have an email address like n.abc@abc-xyz.de and I came up with a simple pattern 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 not allow the dot(.) operator before the @ sign or the entire email contain only one dot operator.

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 shortened:

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

Although entire email contain only one dot operator doesn't seem right requirement since email can be name@google.co.uk also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM