A simple typescript library to validate strings
npm install typescript-validation
yarn add typescript-validation
import validation from "typescript-validation";
validation.validate("example@exmail.com", {
isEmail: {
need: true,
message: "Invalid e-mail",
},
});
getErrors() - Get all errors (Return String[])
getLastError() - Get last error (Return String)
if (validation.success()) {
// Success methods here
} else {
// Unsuccess methods here
console.log(validation.getLastError());
}
import validation from "typescript-validation";
validation.validate("example@exmail.com", {
isEmail: {
need: true,
message: "Invalid e-mail",
},
});
if (validation.success()) {
// Success methods here
} else {
// Unsuccess methods here
console.log(validation.getLastError());
}
need (Boolean): The final expected value (Default value: false)
message (String): Message if the result is not as expected
isAlpha: { need: false, message: "These are not alphabetic characters"}
isEmail: { need: false, message: "This is not an e-mail"}
isEmpty: { need: true, message: "This is empty"}
isNumeric: { need: false, message: "These are not numeric characters"}
min (Number): Minimum characters value
max (Number): Maximum characters value
isLength: { need: true, min: 5, max: 10, message: "This must be between 5 and 10 characters"}