Skip to content

Commit c8a87da

Browse files
darcyclarkeisaacs
authored andcommitted
fix: update email validation
PR-URL: #15 Credit: @ Close: #15 Reviewed-by: @isaacs
1 parent cd75393 commit c8a87da

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

npm-user-validate.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var requirements = exports.requirements = {
1111
},
1212
password: {},
1313
email: {
14+
length: 'Email length must be less then or equal to 254 characters long',
1415
valid: 'Email must be an email address'
1516
}
1617
}
@@ -45,7 +46,10 @@ function username (un) {
4546
}
4647

4748
function email (em) {
48-
if (!em.match(/^.+@.+\..+$/)) {
49+
if (em.length > 254) {
50+
return new Error(requirements.email.length)
51+
}
52+
if (!em.match(/^[^@]+@.+\..+$/)) {
4953
return new Error(requirements.email.valid)
5054
}
5155

test/email.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ test('email misses an @', function (t) {
77
t.end()
88
})
99

10+
test('email is longer then 254 characters', function (t) {
11+
var str = '@'.repeat(255)
12+
var err = v(str)
13+
t.type(err, 'object')
14+
t.end()
15+
})
16+
1017
test('email misses a dot', function (t) {
1118
var err = v('name@domain')
1219
t.type(err, 'object')

0 commit comments

Comments
 (0)