node/deps/npm/node_modules/npm-user-validate/npm-user-validate.js

50 lines
995 B
JavaScript
Raw Normal View History

2013-05-15 05:37:59 +08:00
exports.email = email
exports.pw = pw
exports.username = username
2013-06-19 00:42:42 +08:00
var requirements = exports.requirements = {
username: {
lowerCase: 'Username must be lowercase',
urlSafe: 'Username may not contain non-url-safe chars',
dot: 'Username may not start with "."'
},
password: {
badchars: 'Password passwords cannot contain these characters: \'!:@"'
},
email: {
valid: 'Email must be an email address'
}
};
2013-05-15 05:37:59 +08:00
function username (un) {
if (un !== un.toLowerCase()) {
2013-06-19 00:42:42 +08:00
return new Error(requirements.username.lowerCase)
2013-05-15 05:37:59 +08:00
}
if (un !== encodeURIComponent(un)) {
2013-06-19 00:42:42 +08:00
return new Error(requirements.username.urlSafe)
2013-05-15 05:37:59 +08:00
}
if (un.charAt(0) === '.') {
2013-06-19 00:42:42 +08:00
return new Error(requirements.username.dot)
2013-05-15 05:37:59 +08:00
}
return null
}
function email (em) {
if (!em.match(/^.+@.+\..+$/)) {
2013-06-19 00:42:42 +08:00
return new Error(requirements.email.valid)
2013-05-15 05:37:59 +08:00
}
return null
}
function pw (pw) {
if (pw.match(/['!:@"]/)) {
2013-06-19 00:42:42 +08:00
return new Error(requirements.password.badchars)
2013-05-15 05:37:59 +08:00
}
return null
2013-06-19 00:42:42 +08:00
}