Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
174
rated 0 times [  176] [ 2]  / answers: 1 / hits: 5879  / 3 Years ago, mon, may 3, 2021, 12:00:00

What could be the Regex for accepting .@. as a valid email id? Also need to check the below conditions.



  1. Should contain exactly one @ character.



  2. Before and after @ should consist of at least 1 and at most 64 characters comprising only letters, digits and/or dots(a-z, A-Z, 0-9, .).




was trying with b[w.-]+@[w.-]+.[w]{0,0} but not working as expected.


More From » regex

 Answers
9

/^[a-z0-9.]{1,64}@[a-z0-9.]{1,64}$/i should do the trick (Regex101 explanation):




function demo(str) {
const isEmail = /^[a-z0-9.]{1,64}@[a-z0-9.]{1,64}$/i.test(str);
console.log(isEmail, str);
}

demo('.@.'); // OK
demo('[email protected]'); // OK
demo('a-b_c@a_b'); // Bad chars
demo('a.b.c'); // No @
demo('1234567890123456789012345678901234567890123456789012345678901234@a'); // OK
demo('12345678901234567890123456789012345678901234567890123456789012345@a'); // Too long




[#1401] Sunday, April 25, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
masonm

Total Points: 167
Total Questions: 87
Total Answers: 103

Location: Rwanda
Member since Wed, Jun 8, 2022
2 Years ago
;