Skip to content

Commit

Permalink
use a RFC 2822 regex
Browse files Browse the repository at this point in the history
  • Loading branch information
gumvic committed Jun 28, 2018
1 parent 7907e3e commit 66ae495
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/pattern.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ match = (regex, val, msg, cb) ->

module.exports = v =
emailSync: (email) ->
regex = /^"?['A-Z0-9_%+-]+\.?[A-Z0-9_%+-]*"?[^\.]@\[?([^-_]([A-Z-_]+\.[A-Z]+)+|[0-9]{3}\.[0-9]{3}\.[0-9]{3}\.[0-9]{3})\]?$/i
regex = /^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/
match regex, email

email: (msg = "Invalid Email specified") ->
Expand Down Expand Up @@ -99,4 +99,3 @@ module.exports = v =
(url, cb) ->
return cb(msg) unless v.urlSync(url, opts)
cb()

12 changes: 7 additions & 5 deletions test/fixtures/patterns/emails.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
"\"email\"@example.com",
"1234567890@example.com",
"email@example-one.com",
"email@example",
"_______@example.com",
"email@-example.com",
"email@example.name",
"email@example.museum",
"email@example.co.jp",
"email@12345example.com",
"email@12345sub.67890example.com",
"email@111.222.333.44444",
"firstname-lastname@example.com",
"a'postr'ophe@somewhere.com"
"a'postr'ophe@somewhere.com",
"あいうえお@example.com"
],
"invalid": [
"plainaddress",
Expand All @@ -26,11 +32,7 @@
".email@example.com",
"email.@example.com",
"email..email@example.com",
"あいうえお@example.com",
"email@example.com (Joe Smith)",
"email@example",
"email@-example.com",
"email@111.222.333.44444",
"email@example..com",
"Abc..123@example.com"
]
Expand Down

0 comments on commit 66ae495

Please sign in to comment.