jquery - email regular expression in javascript based on mentioned points -
could 1 please provide regular expression below conditions
- user-part not begin or end “.” character.
- domain-part not contain following invalid characters: "#\"%|<>?'`/ ,*&;:£$^!~ ú(){}+"
- valid email has ‘@’ , ‘.’ character
- valid email not contains 2 consecutive dots
currently using below reg ex
/^(?!^[.])[a-za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-za-z0-9-]+(?:\.[a-za-z0-9-]{2,63})*$/; the mentioned regular expression not working points.
to respect these conditions need treat them in order , take logic write regex in parts, tried make suitable solution case , the regex came with:
(?!^[.])[a-za-z_\-0-9]+[a-za-z_\-0-9.]+(?!\.\.)[^\.]+@(?![#\"%|<>?'`\/ ,*&;:£$^!~ ú(){}+])(?![\.]{2})[a-za-z_\-0-9.]+\.[a-za-z]{2,3} demo:
you can test regex here , see in a working live demo too.
explanation:
- negative lookahead
(?!^[.])
assert regex below not match
^asserts position @ start of string match single character present in list below[.]. matches character.literally (case sensitive)
- match single character present in list below
[a-za-z_\-0-9]+
i added part avoid matching
.in beginning of regex+quantifier — matches between 1 , unlimited times, many times possible, giving needed (greedy)a-zsingle character in range betweena,z(case sensitive),a-zsingle character in range betweena,z_matches character _ literally (case sensitive) - matches character - literally (case sensitive)0-9single character in range between0,9
- match single character present in list below
[a-za-z_\-0-9.]+
+quantifier — matches between 1 , unlimited times, many times possible, giving needed (greedy)a-zsingle character in range betweena,z(case sensitive),a-zsingle character in range betweena,z_matches character _ literally (case sensitive) - matches character - literally (case sensitive)0-9single character in range between0,9,.matches character.literally (case sensitive)
- negative lookahead
(?!\.\.)
assert regex below not match
\.matches character . literally (case sensitive)\.matches character.literally
- match single character not present in list below
[^\.]+
+quantifier — matches between 1 , unlimited times, many times possible, giving needed (greedy)\.matches character.literally
@matches character@literally- negative lookahead
(?![#\"%|<>?'\/ ,*&;:£$^!~ ú(){}+])
assert regex below not match match single character present in list below
[#\"%|<>?'/ ,*&;:£$^!~ ú(){}+]`
- negative lookahead
(?![\.]{2})
assert regex below not match match single character present in list below
[\.]{2},{2}quantifier — matches 2 times\.matches character.literally
- match single character present in list below
[a-za-z_\-0-9.]+
+quantifier — matches between 1 , unlimited times, many times possible, giving neededa-zsingle character in range betweena,z(case sensitive),a-zsingle character in range betweena,z(case sensitive)_matches character _ literally (case sensitive) - matches character - literally (case sensitive)0-9single character in range between0,9,.matches character.literally (case sensitive)\.matches character.literally
- match single character present in list below
[a-za-z]{2,3}
{2,3}quantifier — matches between2,3times, many times possible, giving neededa-zsingle character in range betweena,z(case sensitive),a-zsingle character in range betweena,z
Comments
Post a Comment