Skip to content

Commit

Permalink
fix: update email validation
Browse files Browse the repository at this point in the history
PR-URL: #15
Credit: @
Close: #15
Reviewed-by: @isaacs
  • Loading branch information
darcyclarke authored and isaacs committed Oct 15, 2020
1 parent cd75393 commit c8a87da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion npm-user-validate.js
Expand Up @@ -11,6 +11,7 @@ var requirements = exports.requirements = {
},
password: {},
email: {

This comment has been minimized.

Copy link
@510sss
length: 'Email length must be less then or equal to 254 characters long',
valid: 'Email must be an email address'
}
}
Expand Down Expand Up @@ -45,7 +46,10 @@ function username (un) {
}

function email (em) {
if (!em.match(/^.+@.+\..+$/)) {
if (em.length > 254) {
return new Error(requirements.email.length)
}
if (!em.match(/^[^@]+@.+\..+$/)) {
return new Error(requirements.email.valid)
}

Expand Down
7 changes: 7 additions & 0 deletions test/email.test.js
Expand Up @@ -7,6 +7,13 @@ test('email misses an @', function (t) {
t.end()
})

test('email is longer then 254 characters', function (t) {
var str = '@'.repeat(255)
var err = v(str)
t.type(err, 'object')
t.end()
})

test('email misses a dot', function (t) {
var err = v('name@domain')
t.type(err, 'object')
Expand Down

0 comments on commit c8a87da

Please sign in to comment.