I'm updating Webmail, a web-based email client that is one of my older projects. I wanted to add client-side validation to the To:, Cc:, and Bcc: fields in the composition form, but I quickly realized that a simple regular expression match for one valid email address wouldn't ensure that the whole field was valid because there would likely be multiple emails in each of those fields. Plus, each email may or may not have a name in front of it. So here's how I coded the JavaScript function to validated multiple name-formatted emails in real time.
The code works by looking for correctly formatted emails separated by delimiters (semi-colons, in this case). If a string is typed in that isn't complete or correct, the background of the input field changes color to let the user know that they need to correct it. Below is a working demo-- enter your email address, or your email address surrounded by angle brackets:

Post a comment