-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdefaultRules.ts
More file actions
39 lines (37 loc) · 1.19 KB
/
defaultRules.ts
File metadata and controls
39 lines (37 loc) · 1.19 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
import dayjs from 'dayjs';
// Custom default rules to validate form fields
const defaultRules = {
numbers: /^(([0-9]*)|(([0-9]*)\.([0-9]*)))$/,
email:
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
required: /\S+/,
hasNumber: /\d/,
hasUpperCase: /(?=.*[A-Z])/,
hasLowerCase: /(?=.*[a-z])/,
hasSpecialCharacter: /(\W)/,
date(format = 'YYYY-MM-DD', value: string) {
const d = dayjs(value, format);
if (d == null || !d.isValid()) return false;
return true;
},
minlength(length: number, value: string) {
if (length === void 0) {
throw 'ERROR: It is not a valid length, checkout your minlength settings.';
} else if (value.length >= length) {
return true;
}
return false;
},
maxlength(length: number, value: string) {
if (length === void 0) {
throw 'ERROR: It is not a valid length, checkout your maxlength settings.';
} else if (value.length > length) {
return false;
}
return true;
},
equalPassword(dataToCompare: string, value: string) {
return dataToCompare === value;
}
};
export default defaultRules;