Last active
October 13, 2019 17:14
-
-
Save GergKllai1/9f75d336f5852d9c6f2d8d05377f1105 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const passwordConfirmationRule = value => { | |
let password = document.getElementById("password"); | |
return value === password.value | |
? false | |
: "Password confirmation must match password."; | |
}; | |
export const emailRule = value => { | |
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value) ? false : "Not a valid email."; | |
}; | |
export const required = value => { | |
return value.length > 0 ? true : false; | |
}; | |
export const minimumCharacters = (value, target) => { | |
return target <= value.length | |
? false | |
: `Minimum length is ${target} characters.`; | |
}; | |
export const minimumUpperCaseCharacters = (value, target) => { | |
const valueArray = value.split(""); | |
const upperCases = valueArray.filter( | |
char => /^[^a-z]*$/.test(char) && char | |
); | |
return upperCases.length >= target | |
? false | |
: `Must contain at least ${target} uppercase characters.`; | |
}; | |
export const minimumNumberCharacters = (value, target) => { | |
const valueArray = value.split(""); | |
const numbers = valueArray.filter(char => char <= "9" && char >= "0" && char); | |
return numbers.length >= target | |
? false | |
: `Must contain at least ${target} numerical characters.`; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment