This repository was archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathname.js
More file actions
120 lines (105 loc) · 2.06 KB
/
Copy pathname.js
File metadata and controls
120 lines (105 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const suffixOptions = [
'',
'Jr',
'Sr',
'II',
'III',
'IV',
'V',
'VI',
'VII',
'VIII',
'IX',
'X',
'Other'
]
export default class NameValidator {
constructor(data = {}) {
this.first = data.first
this.firstInitialOnly = data.firstInitialOnly
this.last = data.last
this.middleInitialOnly = data.middleInitialOnly
this.noMiddleName = data.noMiddleName
this.hideMiddleName = data.hideMiddleName
this.middle = data.middle
this.suffix = data.suffix
this.suffixOther = data.suffixOther
}
/**
* Validates a persons first name
*/
validFirst() {
if (!this.first) {
return false
}
if (this.firstInitialOnly && this.first.length > 1) {
return false
}
return true
}
/**
* Validates a persons last name
*/
validLast() {
if (!this.last) {
return false
}
return true
}
/**
* Validates a persons middle name
*/
validMiddle() {
if (this.hideMiddleName) {
return true
}
switch (this.noMiddleName) {
case true:
// If user does not have a middle name, make sure middle name is not entered
if (this.middle) {
return false
}
break
case false:
// User should have a middle name or initial
if (!this.middle) {
return false
}
if (this.middleInitialOnly && this.middle.length > 1) {
return false
}
break
default:
return false
}
return true
}
/**
* Validates a users suffix
*/
validSuffix() {
// Suffix is optional
if (!this.suffix) {
return true
}
let found = false
for (let validSuffix of suffixOptions) {
if (validSuffix === this.suffix) {
found = true
}
}
if (!found) {
return false
}
if (this.suffix === 'Other' && !this.suffixOther) {
return false
}
return true
}
/**
* Validates all portions of a persons name
*/
isValid() {
return this.validFirst() && this.validLast() && this.validMiddle()
}
}