Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
How to validate the Display Name and Email Address together in a string using JavaScript or jQuery?

How to validate a Display Name and Email Address in the following format?

"John Doe" johndoe@example.com

After doing the necessary research, the closest SO question I can relate my requirements to is: Extract email and name with regex

However, I couldn't find something solid, online. I am posting this question here in case someone has already developed a solution that they can share with everyone.

Wishful thinking is that if it can behave like MailAddress Class from System.Net.Mail namespace. https://docs.microsoft.com/en-us/dotnet/api/system.net.mail.mailaddress

function ValidateEmailAndDisplayName(emailAddressWithDisplayName) {
    // A solid logic that addresses following test cases.
}

Quouted Display Name: ","

emailAddressWithDisplayName = "John Doe" <johndoe@example.com> //=> True

Display Name without double qoutes:

emailAddressWithDisplayName = John Doe <johndoe@example.com> //=> True

Comma in Quouted Display Name: ","

emailAddressWithDisplayName = "Doe, John" <johndoe@example.com> //=> True

Comma in Display Name without double qoutes: ,

emailAddressWithDisplayName = Doe, John <johndoe@example.com> //=> True

Backslash before adding double qoute: \

emailAddressWithDisplayName = "John \"Middle Name\" Doe" <johndoe@example.com> //=> True

Missing backslash before adding double qoute: \

ValidateEmailAndDisplayName('"John "Middle Name" Doe" <johndoe@example.com>'); //=> False

Missing closing angular bracket: >

emailAddressWithDisplayName = "John Doe" <johndoe@example.com //=> Flase

TIA

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!