initial commit
This commit is contained in:
32
resources/js/Validation/validators.js
vendored
Normal file
32
resources/js/Validation/validators.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
export default function useValidators() {
|
||||
|
||||
const isEmpty = (fieldName, fieldValue) => {
|
||||
return !fieldValue ? `The ${fieldName} is required`:"";
|
||||
}
|
||||
|
||||
const minLength = (fieldName, fieldValue, min) => {
|
||||
return fieldValue.length < min ? `The ${fieldName} field must be at least ${min} characters long` : "";
|
||||
}
|
||||
|
||||
const maxLength = (fieldName, fieldValue, max) => {
|
||||
return fieldValue.length > max ? `The ${fieldName} cannot be greater than ${max} characters long` : "";
|
||||
}
|
||||
|
||||
const isEmail = (fieldName, fieldValue) => {
|
||||
let re = /^(([^<>()[\]\\.,;:\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,}))$/;
|
||||
return !re.test(fieldValue) ? "The input is not a valid " + fieldName + " address" : "";
|
||||
}
|
||||
|
||||
const isNum = (fieldName, fieldValue) => {
|
||||
let isNum = /^\d+$/.test(fieldValue);
|
||||
return !isNum ? "The " + fieldName + " field only have numbers" : "";
|
||||
}
|
||||
|
||||
const isInt = (fieldName, fieldValue) => {
|
||||
let test = /^\d+$/.test(fieldValue);
|
||||
return !test ? "The " + fieldName + " must be integer" : "";
|
||||
}
|
||||
|
||||
return { isEmpty, minLength, isEmail, isNum,isInt,maxLength}
|
||||
}
|
||||
Reference in New Issue
Block a user