How to Validate Non-English (Utf-8) Encoded Email Address in JavaScript and PHP

How to validate non-english (UTF-8) encoded email address in Javascript and PHP?

Attempting to validate email addresses may not be a good idea. The specifications (RFC5321, RFC5322) allow for so much flexibility that validating them with regular expressions is literally impossible, and validating with a function is a great deal of work. The result of this is that most email validation schemes end up rejecting a large number of valid email addresses, much to the inconvenience of the users. (By far the most common example of this is not allowing the + character.)

It is more likely that the user will (accidentally or deliberately) enter an incorrect email address than in an invalid one, so actually validating is a great deal of work for very little benefit, with possible costs if you do it incorrectly.

I would recommend that you just check for the presence of an @ character on the client and then send a confirmation email to verify it; it's the most practical way to validate and it confirms that the address is correct as well.

How to validate email (internationally) for secure saving in database

In case someone is looking for an answer to this question, Now after two years of working as a developer I would agree with Alex Howansky comment:

Preventing SQL injection doesn't happen by ensuring you have a valid email address, it happens by using prepared statements with bound parameters.

Validate email address in Javascript, and compatible with non-ASCII characters

Don't overcomplicate things, please.

Take a moment and think about why you need that. Most likely because you want to send your user an email, right? So I'd advocate for the easiest email validation regex there is:

/@/

Done. It will validate all valid email addresses. It will also incorrectly validate a lot of stuff that just looks like one but isn't actually valid, but most errors are either not filling out a form field or confusing fields and entering the wrong things in other fields.

Also you'll notice if an email address isn't valid because your mails bounce. And existence of an address is something no regex can ever do for you.



Related Topics



Leave a reply



Submit