jquery - email regular expression in javascript based on mentioned points -


could 1 please provide regular expression below conditions

  1. user-part not begin or end “.” character.
  2. domain-part not contain following invalid characters: "#\"%|<>?'`/ ,*&;:£$^!~ ú(){}+"
  3. valid email has ‘@’ , ‘.’ character
  4. 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 between a , z (case sensitive), a-z single character in range between a , z _ matches character _ literally (case sensitive) - matches character - literally (case sensitive) 0-9 single character in range between 0 , 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 between a , z (case sensitive), a-z single character in range between a , z _ matches character _ literally (case sensitive) - matches character - literally (case sensitive) 0-9 single character in range between 0 , 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 needed a-z single character in range between a , z (case sensitive), a-z single character in range between a , z (case sensitive) _ matches character _ literally (case sensitive) - matches character - literally (case sensitive) 0-9 single character in range between 0 , 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 between 2 , 3 times, many times possible, giving needed a-z single character in range between a , z (case sensitive), a-z single character in range between a , z


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -