DEV Community

Yuki Kimoto
Yuki Kimoto

Posted on • Updated on

Checking Mail Address Simply using Perl Regular Expression

Let't check mail address simply using Perl regular expression.

if ($mail =~ /^.+\@.+$/a) {

}
Enter fullscreen mode Exit fullscreen mode

This means $mail is

[one more ASCII]@[one more ASCII]
Enter fullscreen mode Exit fullscreen mode

Improvement

ASCII graphic characters are a little better.

/^\p{PosixGraph}+\@\p{PosixGraph}+$/
Enter fullscreen mode Exit fullscreen mode

Discussion (7)

Collapse
yukikimoto profile image
Yuki Kimoto Author

ASCII graphic characters are a little better. Spaces are not good.

/^\p{PosixGraph}+\@\p{PosixGraph}+$/
Enter fullscreen mode Exit fullscreen mode
Collapse
aarone4 profile image
Aaron Reese

How far down the regex rabbit hole do you want to go?
Must start with a letter/number
Can have one period before the @
Can't have more than one period
Cannot have spaces
Must be at least one letter/number between period and @
Must be at least one letter/number immediately after @
Must be a period after @
Must be at least two characters after the period
Can be a second period after the min 2 chars if they are co
Must be 2 chars after the the second period
They must match a list of country codes.

Collapse
yukikimoto profile image
Yuki Kimoto Author

Thank you for your information.

Collapse
moopet profile image
Ben Sinclair

"hello world.."@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0000:7324].

Collapse
yukikimoto profile image
Yuki Kimoto Author

Oh, this is valid in my regex.

Collapse
basman profile image
Adam.S

I prefer the Email::Valid module. And Email::Valid::Loose which used to be very handy with older phone email addresses provided in japan.

Collapse
yukikimoto profile image
Yuki Kimoto Author

Thank you for information.