Email allowed chars regex?

What are the mostly used and allowed by email providers chars?

I wanna create a regex to only allow those!

this is mine:

^[A-Za-z0-9.@_+-]*$

keep SQL injection in mind!!!

This wiki seems to give an easier-to-read list of acceptable characters than the RFC does: https://en.wikipedia.org/wiki/Email_address

Isn’t there a standard method of doing this now? You’d think there wouldn’t be a need to do email address validation from scratch any more.

Thanks buddy theory is good but it’s not practical. Which are mostly allowed by top websites?

Surely any that are allowed by the specification will be allowed by all mail transports? If you want to run an email service, I don’t think you can pick and choose which characters you will support, if it’s in the spec you need to allow it. What happens if your mail server gets an email from a perfectly valid email address, but you’ve decided not to support it?

Makes sense but how come then facebook or twitter won’t allow them there has got to be a reason!

Which characters from the email spec do those sites not allow? That does seem to be a strange thing to do.

The HTML implementation of ‘email’ type is defined as [1]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)*$


  1. a-zA-Z0-9.!#$%&’*+/=?^_`{|}~- ↩︎

Head over to Facebook and try to enter email with special chars. It will say invalid email.

Which specific special characters? Any that are in the list that @m_hutley posted above?

What problem are you trying to solve exactly?
You can use PHP’s built in email validation in filter_var() without needing any complex or error prone regex.

Prepared statements when you insert, select, ect.
Though there is a Sanitize filter in filter_var() too if you want it.

Reminds me of this post

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.