refs #5858 feat: add format validation
gitea/salix-front/pipeline/head This commit looks good Details

This commit is contained in:
Javier Segarra 2023-11-22 07:12:34 +01:00
parent 701f1e100f
commit 333050b6a7
1 changed files with 9 additions and 0 deletions

View File

@ -37,6 +37,15 @@ export function useValidator() {
const { t } = useI18n();
const validations = function (validation) {
return {
format: (value) =>{
const {allowNull, with: format, allowBlank} = validation;
const message = t(validation.message) || validation.message;
if(!allowBlank && value ==='') return message
if(!allowNull && value === null) return message
const isValid = new RegExp(format).test(value)
if(!isValid) return message
},
presence: (value) => {
let message = `Value can't be empty`;
if (validation.message)