|
@@ -0,0 +1,47 @@
|
|
|
+export default function validate(values) {
|
|
|
+ const { name, email, password, passwordConfirmation } = values;
|
|
|
+ const errors = {};
|
|
|
+
|
|
|
+ if (!email) {
|
|
|
+ errors.email = "Required";
|
|
|
+ }
|
|
|
+ else if (email.length < 8 || email.length > 20) {
|
|
|
+ errors.email = "Invalid email length: email should be from 8 to 20 symbols";
|
|
|
+ }
|
|
|
+ else if (
|
|
|
+ !/^(([^<>()\]\\.,;:\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,}))$/.test(email)) {
|
|
|
+ errors.email = "Invalid email, try another one";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!name) {
|
|
|
+ errors.name = "Required";
|
|
|
+ }
|
|
|
+ else if (name.length < 6 || name.length > 10) {
|
|
|
+ errors.name = "Invalid name length: name should be from 6 to 10 symbols";
|
|
|
+ }
|
|
|
+ else if (!/^[_A-z0-9]*((-|\s)*[_A-z0-9])*$/.test(name)) {
|
|
|
+ errors.name = "Invalid name, try another one"
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!password) {
|
|
|
+ errors.password = "Required"
|
|
|
+ }
|
|
|
+ else if (/[,]/.test(password)) {
|
|
|
+ errors.password = "Invalid symbol: \",\" is not allowed!";
|
|
|
+ }
|
|
|
+ else if (password.length < 8 || password.length > 20) {
|
|
|
+ errors.password = "Invalid password length: password should be from 8 to 20 symbols";
|
|
|
+ }
|
|
|
+ else if (!/^[a-z0-9_-]{8,20}$/i.test(password)) {
|
|
|
+ errors.password = "Invalid password, try another one";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!passwordConfirmation) {
|
|
|
+ errors.passwordConfirmation = "Required";
|
|
|
+ }
|
|
|
+ else if (password !== passwordConfirmation) {
|
|
|
+ errors.passwordConfirmation = "Passwords don't match each other!";
|
|
|
+ }
|
|
|
+
|
|
|
+ return errors;
|
|
|
+}
|