0

I am using below regex for email address validation. Issue is if the domain part (that is after @) is ending with dot(.) it is considering it as valid address instead of failing it.

regex = /^((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x20\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(\[(?:[:0-9A-Za-z]+)\])|(?:[:0-9A-Za-z]+)))/;   

Below are few emails of which are allowed and not allowed. Please suggest.

sample@exam - valid,
sample@exam.com - valid,
sample@exam.com.in - valid,
sample@.exam - invalid,
sample@exam. - invalid,
Matt.G
  • 3,586
  • 2
  • 10
  • 23
shaaa
  • 227
  • 1
  • 7
  • 22

0 Answers0