Skip to content

Instantly share code, notes, and snippets.

@xardit
Created February 27, 2022 12:59
Show Gist options
  • Save xardit/8fc72b0f7041fa653e970f149029afe2 to your computer and use it in GitHub Desktop.
Save xardit/8fc72b0f7041fa653e970f149029afe2 to your computer and use it in GitHub Desktop.
node yup validation schema example
import { string, number, object } from "yup";
// import { passwordResetRequestVerifyCode } from "./session.server";
const uuid = string().uuid("Gabim në identifikimin e linkut!");
const vatid = string().matches(
/^([a-z][0-9]{8,10}[a-z])$/gi,
"Numri NIPT është gabim! (Shembull X12345678X)"
);
const password = string().min(6).max(128);
const loginType = string().oneOf(
["login", "register"],
"Gabim në metodën e hyrjes"
);
const fullname = string()
.min(4)
.matches(
/^([a-z]+\s[a-z]+\s*[a-z]*)$/gi,
'Emri nuk është në formatin e saktë "Emër Mbiemër"'
);
const companyName = string()
.min(2)
.matches(
/^([\w\sçë\-_.,]{2,})$/gi,
"Emri kompanise duhet të paktën 2 karaktere"
);
const email = string().email("Email është gabim");
const repeatedPassword = string().test(
"passwords-match",
"Fjalëkalimi duhet të jetë i njëjtë",
function (value) {
return this.parent.password === value;
}
);
const redirectUrl = string().matches(/^([\/][^\/])/g, "Gabim në link");
const phone = string().matches(
/^([+]*[0-9]{10,20})$/g,
"Numri telefonit nuk është në formatin e saktë 0681122333 ose +355681122333"
);
export const Schema_forgot_password_code = object().shape({
code: uuid
// .test(
// "reset-password-verify-code",
// "Linku është gabim ose ka skaduar!",
// (code) => passwordResetRequestVerifyCode(code || "-")
// ),
.required(),
password: password.required(),
repeatedPassword: repeatedPassword.required(),
});
Schema_forgot_password_code.validate({
code: "3732a490-46d8-4be0-96c5-b6f04ca891e6ZZZZZZ",
password: "123456",
repeatedPassword: "123456",
})
.then((OK) => {
console.log("OK", OK);
})
.catch((ERR) => {
console.log("ERR", ERR.errors);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment