Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update email validation #15

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion npm-user-validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var requirements = exports.requirements = {
},
password: {},
email: {
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
Original file line number Diff line number Diff line change
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