-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomValidation.js
30 lines (26 loc) · 954 Bytes
/
customValidation.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
27
28
29
30
const isNameFormatValid = (name) => {
// source: https://stackoverflow.com/questions/2385701/regular-expression-for-first-and-last-name
const nameRegEx = /^[^0-9_!¡?÷?¿/\\+=@#$%^&*(){}|~<>;:[\]]{2,}$/ // ! test more
return nameRegEx.test(name)
}
const isEmailValid = (email = '') => {
const emailRegEx = /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(.\w{2,3})+$/
return emailRegEx.test(email)
/* regex from validator-js package (uninstalled package)
new RegExp("^[a-z0-9._%-]+@[a-z0-9.-]*[a-z0-9]{1}\.[a-z]{2,4}$", "i")
* regex = /^[a-z0-9._%-]+@[a-z0-9.-]*[a-z0-9]{1}\.[a-z]{2,4}$/i
*/
}
const isUsernameValid = (username = '') => {
const usernameRegEx = /\w+/
return usernameRegEx.test(username) && username.length >= 6
}
const isPasswordMatching = (password = '', password2 = '') => {
return password && password2 && password === password2
}
export {
isNameFormatValid,
isEmailValid,
isUsernameValid,
isPasswordMatching,
}