codekingpro/portable-devtools
114k
1exports.email = email
2exports.pw = pw
3exports.username = username
4var requirements = exports.requirements = {
5 username: {
6 length: 'Name length must be less than or equal to 214 characters long',
7 lowerCase: 'Name must be lowercase',
8 urlSafe: 'Name may not contain non-url-safe chars',
9 dot: 'Name may not start with "."',
10 illegal: 'Name may not contain illegal character',
11 },
12 password: {},
13 email: {
14 length: 'Email length must be less then or equal to 254 characters long',
15 valid: 'Email must be an email address',
16 },
17}
18
19var illegalCharacterRe = new RegExp('([' + [
20 "'",
21].join() + '])')
22
23function username (un) {
24 if (un !== un.toLowerCase()) {
25 return new Error(requirements.username.lowerCase)
26 }
27
28 if (un !== encodeURIComponent(un)) {
29 return new Error(requirements.username.urlSafe)
30 }
31
32 if (un.charAt(0) === '.') {
33 return new Error(requirements.username.dot)
34 }
35
36 if (un.length > 214) {
37 return new Error(requirements.username.length)
38 }
39
40 var illegal = un.match(illegalCharacterRe)
41 if (illegal) {
42 return new Error(requirements.username.illegal + ' "' + illegal[0] + '"')
43 }
44
45 return null
46}
47
48function email (em) {
49 if (em.length > 254) {
50 return new Error(requirements.email.length)
51 }
52 if (!em.match(/^[^@]+@.+\..+$/)) {
53 return new Error(requirements.email.valid)
54 }
55
56 return null
57}
58
59function pw () {
60 return null
61}
62 