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.
^[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.
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
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)