-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules.js
26 lines (24 loc) · 945 Bytes
/
rules.js
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
// Customizable settings
let emailValidationRegex = /.+@.+\..+/;
let passwordMinLength = 8;
let passwordValidationRegex = () =>
new RegExp(`^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{${passwordMinLength},})`);
// Return rules, eventually with customizazions
const getRules = () => ({
email: [v => emailValidationRegex.test(v) || "E-mail must be valid"],
password: [
v =>
passwordValidationRegex().test(v) ||
`Min. ${passwordMinLength} characters with at least one capital letter and a number.`
],
required: [v => !!v || "This field is required"]
});
export const customizeRules = settings => {
if (settings.emailValidationRegex)
emailValidationRegex = settings.emailValidationRegex;
if (settings.passwordMinLength)
passwordMinLength = settings.passwordMinLength;
if (settings.passwordValidationRegex)
passwordValidationRegex = () => settings.passwordValidationRegex;
};
export const rules = getRules();