silence_ghost
silence_ghost

Reputation: 3

how to validate multiple emails in javascript?

I have a multiple emails seperated by commas. How to validate all these emails field using javascript.

Upvotes: 0

Views: 698

Answers (1)

Piskvor left the building
Piskvor left the building

Reputation: 92752

  • split() the string into an array by commas
  • for every array element, run the validation

What to validate in an e-mail address is a bit of a contentious topic (for example [email protected] is actually a valid e-mail address, but most naïve validators reject it) - checking for a part before the @, and a probably-valid domain name after the @ (anything separated by a dot, due to the complex mess that is TLDs these days) should be sufficient.

(why not validate the domain: you'll get it wrong. That's nothing personal, everyone gets it wrong: you, me, everyone - what with internationalized domain names, domain names longer than 4 characters, alternate DNS roots, internal domains, new domains approved each year, etc etc. If the mail bounces, too bad - but trying to validate the domain in JS is rather futile.)

Upvotes: 1

Related Questions