2018-01-31 01:21:21 +03:00
|
|
|
export default {
|
|
|
|
/**
|
|
|
|
* Validate a required field.
|
|
|
|
* @param {Object} field
|
|
|
|
* @param {string} label
|
|
|
|
*/
|
2018-02-01 18:47:11 +03:00
|
|
|
async required ({value, error}) {
|
2018-02-01 01:20:29 +03:00
|
|
|
return (!value || (Array.isArray(value) && !value.length)) ? error(...arguments) : false
|
2018-01-31 01:21:21 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate email addresses
|
|
|
|
* @param {Object} field
|
|
|
|
* @param {string} label
|
|
|
|
*/
|
2018-02-01 18:47:11 +03:00
|
|
|
async email ({value, error}) {
|
2018-01-31 01:21:21 +03:00
|
|
|
// eslint-disable-next-line
|
|
|
|
var re = /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;
|
|
|
|
return (value && !re.test(value.toLowerCase())) ? error(...arguments) : false
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a particular field is matches another field in the form.
|
|
|
|
* @param {Object} field
|
|
|
|
* @param {string} label
|
|
|
|
* @param {string} confirmField (uses `${field}_confirmation` by default)
|
|
|
|
*/
|
2018-02-01 18:47:11 +03:00
|
|
|
async confirmed ({field, value, error, values}, confirmField) {
|
2018-01-31 01:21:21 +03:00
|
|
|
confirmField = confirmField || `${field}_confirmation`
|
|
|
|
return (value && value !== values[confirmField]) ? error(...arguments) : false
|
|
|
|
}
|
|
|
|
}
|