vue-vuelidate-jsonschema
Version:
Create validation definitions for vuelidate based on json schema
14 lines (12 loc) • 351 B
JavaScript
var vuelidate = require('vuelidate')
var isString = require('lodash/isString')
module.exports = function patternValidator(propertySchema, pattern) {
return vuelidate.withParams({
type: 'schemaPattern',
pattern: pattern,
schema: propertySchema
}, function(val) {
if (!isString(val)) return true
return pattern.test(val)
})
}