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-z
single character in range betweena
,z
(case sensitive),a-z
single character in range betweena
,z
_
matches character _ literally (case sensitive) - matches character - literally (case sensitive)0-9
single 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-z
single character in range betweena
,z
(case sensitive),a-z
single character in range betweena
,z
_
matches character _ literally (case sensitive) - matches character - literally (case sensitive)0-9
single 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-z
single character in range betweena
,z
(case sensitive),a-z
single character in range betweena
,z
(case sensitive)_
matches character _ literally (case sensitive) - matches character - literally (case sensitive)0-9
single 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
,3
times, many times possible, giving neededa-z
single character in range betweena
,z
(case sensitive),a-z
single character in range betweena
,z
Comments
Post a Comment