user18042993
user18042993

Reputation:

regex email valid despite missing dot extension

I've this regex for email

^[_a-z0-9-]+(\.[_a-z0-9-]+)*(\+[a-z0-9-]+)?@[a-z0-9-]+(\.[a-z0-9-]+)*$

my test case is johnd@c but it returned true. What's wrong here?

https://codesandbox.io/s/regex-forked-h7r6wk?file=/src/index.js:180-187

Upvotes: 0

Views: 100

Answers (1)

NullVoid
NullVoid

Reputation: 847

This will work:

^[_a-z0-9-]+(\.[_a-z0-9-]+)*(\+[a-z0-9-]+)?@[a-z0-9-]+(\.[a-z0-9-]+)$

Please note that your regex may not perfectly fit all cases nor match all cases in RFC 5322.

Upvotes: 1

Related Questions