gancio-upstream/plugins/validators.js
2021-10-18 15:45:16 +02:00

19 lines
597 B
JavaScript

const linkify = require('linkifyjs')
export default ({ app }, inject) => {
const $t = app.i18n.t.bind(app.i18n)
const validators = {
required (fieldName) {
return value => !!value || $t('validators.required', { fieldName: $t(fieldName) })
},
email: [
v => !!v || $t('validators.required', { fieldName: $t('common.email') }),
v => (v && (v === 'admin' || !!linkify.test(v, 'email')) || $t('validators.email'))
],
password: [
v => !!v || $t('validators.required', { fieldName: $t('common.password') })
]
}
inject('validators', validators)
}