gancio-upstream/plugins/validators.js

26 lines
801 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) {
return v => !(v===undefined || v===null || v.length <= 0) || $t('validators.required', { fieldName: $t(fieldName) })
2020-09-05 01:21:47 +02:00
},
email: [
v => !!v || $t('validators.required', { fieldName: $t('common.email') }),
2021-10-18 15:45:16 +02:00
v => (v && (v === 'admin' || !!linkify.test(v, 'email')) || $t('validators.email'))
2020-09-05 01:21:47 +02:00
],
password: [
v => !!v || $t('validators.required', { fieldName: $t('common.password') })
],
latitude: [
v => (v < 90 && v > -90) || $t('validators.latitude')
],
longitude: [
v => (v < 180 && v > -180) || $t('validators.longitude')
2020-09-05 01:21:47 +02:00
]
}
inject('validators', validators)
}