Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

125
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda