0
("^[_a-zA-Z0-9!#$%&'*+-/=?^_`{|}~;]+(\\.[_a-zA-Z0-9!#$%&'*+-/=?^_`{|}~;]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z]{2,})$")

This is my regex for email field but I don't want to allow spaces in email. What I have to do please suggest me??

PrakashG
  • 1,642
  • 5
  • 20
  • 30
user21
  • 1
  • 2

1 Answers1

1

Unless you are trying to validate the email address as originating from a known domain, validating is practically impossible and bound to be frustrating for users with unusual addresses that your regex fails validation on.

For reference: https://davidcel.is/posts/stop-validating-email-addresses-with-regex/

Here is your current regex compared against a list of valid and invalid email addresses. As you can see, you failed to allow several, perfectly valid email addresses while still letting through around 30% of the invalid ones.

James Coyle
  • 9,922
  • 1
  • 40
  • 48
  • Do not use regex for email validation. It doesn't work. Use a front end library such as [mailcheck](https://github.com/mailcheck/mailcheck) to assist users when typing in their address but allow the user to enter what they want. Then send an email to that address and make the user click a link within that email to confirm it is a valid address. – James Coyle Feb 07 '19 at 09:57