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

228
Visualizações
Email Validation refined

I have following regex for email validation

/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;

only issue with this or similar solution available is that 123@domain.com passes this regex.

I do not want any email to start with a digit.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

^[a-zA-Z0-9.!#$%&'+/=?^_`{|}~-]+@

This is the part of the regex that matches everything up to the @ separator. 0-9. matches any digit. So create a new phrase before that that doesn't match 0-9. Then change the quantifier (currently +, at least 1) to * (0 or more) so that emails with only one character work (as long as it's not a number of course).

^[a-zA-Z.!#$%&'+/=?^_`{|}~-][a-zA-Z0-9.!#$%&'+/=?^_`{|}~-]*@

See https://regex101.com/r/qjdZ0A/1 for an interactive example.

about 4 years ago · Juan Pablo Isaza Relatório

0

Prepend the expression of the email with a negative lookahead...

^(?![0-9])+[a-zA-Z0-9.!#$%&'+=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)$
 _________

This only matches the email if the first character is NOT 0-9

about 4 years ago · Juan Pablo Isaza Relatório

0

reg07 is what you need.

Code includes the process into building it

const stringToTest = "zaz234@microshit.kazo"

// Ideal
const regex = new RegExp('(^[^@.]+)@([^@.]+)\.{1}(\w{1,6}$)');
const reg = /(^(.+?))@(.+?).(\w{1,6})/;

const reg00 = /(^(.+)@)/;
const reg01 = /(^[^@]+)@/;
const reg02 = /(^[^@]+)@([^@]+)/;
const reg03 = /(^[^@]+)@([^@]+)\.{1}/;
const reg04 = /(^[^@]+)@([^@]+)\.{1}(\w+)/;
const reg05 = /(^[^@]+)@([^@]+)\.{1}(\w{2,4})/;
const reg06 = /(^[^@]+)@([^@]+)\.{1}(\w{1,6}$)/;
const reg07 = /(^[^@.]+)@([^@.]+)\.{1}(\w{1,6}$)/;

console.log(`We are testing this RexEx:\n${reg07}\n\nTo see if matches this string:\n${stringToTest}\n\nResults:`)
const booleanReg = reg07.test(stringToTest) 
const arrayReg = reg07.exec(stringToTest)

console.log(`1.Simeple Match:\n${booleanReg}\n2.Array Match:\n${arrayReg}`)
const emailInfo = {
  emailUserName: arrayReg[1],
  emailProvider: arrayReg[2],
  emailExtention: arrayReg[3]
}

console.log(`\n\nemail objet build:\n\n`, emailInfo)

about 4 years ago · Juan Pablo Isaza Relatório
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