Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cooperino's avatar

What is the regex of email:rfc.dns validation rule?

Does anyone know the regex equivalent for the email:rfc.dns validation rule? I need it for the front end (JavaScript) but couldn't exactly match it so right now my frontend allows certain email addresses that my backend won't and it's bad for UX since it shows these email addresses as valid

*Using Laravel 8: https://laravel.com/docs/8.x/validation#rule-email

Edit: It uses this package: https://github.com/egulias/EmailValidator , is it even possible to "convert" this package validation of emails into 1 regex? (when using the rfc and dns rules)

0 likes
4 replies
Niush's avatar

DNS Validation checks if the domain name in the provided email address is accepting emails (MX records etc.). You could technically do that from the front-end using some APIs, but that is totally not necessary. You should not do exact validation in the frontend as well. Just let the backend handle the hard work. (It is not regex based)

RFC Validation is very complex and has different varieties. This: https://gist.github.com/badsyntax/719800 , and much more complex. Again, I would just stick with basic validation in the front-end.

For example: You could do compromised password validation in the frontend, but you normally wouldn't.

1 like
cooperino's avatar

@Niush Thanks, I ended up using a simple regex for just a basic email structure, as I'm sending email to verify the address and there is no point messing with it too much then, it only complicates the things in my opinion

ajay01's avatar

Dose it really solve the problem? Because I faced the similar issue my users were misspelling word gmail.com to gmsil.com. but It still allowing it because gmsil.com is valid domain name. But if I try [email protected] any random string as email front and gmsil.comstill it is allowing it.

Please or to participate in this conversation.