gancio-upstream/plugins/validators.js

20 lines
578 B
JavaScript
Raw Normal View History

2020-09-05 01:21:47 +02:00
const linkify = require('linkifyjs')
export default ({ app }, inject) => {
const $t = app.i18n.t.bind(app.i18n)
const validators = {
required (fieldName) {
2020-10-07 10:09:00 +02:00
return value => !!value || $t('validators.required', { fieldName: $t(fieldName) })
2020-09-05 01:21:47 +02:00
},
email: [
v => !!v || $t('validators.required', { fieldName: $t('common.email') }),
v => (v && !!linkify.test(v, 'email')) || $t('validators.email')
],
password: [
v => !!v || $t('validators.required', { fieldName: $t('common.password') })
]
}
inject('validators', validators)
}