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) {
|
2023-04-09 23:40:16 +02:00
|
|
|
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') })
|
2023-02-17 00:23:35 +01:00
|
|
|
],
|
|
|
|
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)
|
|
|
|
}
|