adds missing files
This commit is contained in:
parent
e8d8bb67ee
commit
b10c41143f
2 changed files with 27 additions and 0 deletions
15
packages/builder/src/helpers/validation/validation.js
Normal file
15
packages/builder/src/helpers/validation/validation.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { writable, derived } from 'svelte/store'
|
||||||
|
|
||||||
|
export function createValidationStore(initialValue, ...validators) {
|
||||||
|
|
||||||
|
const value = writable(initialValue || '')
|
||||||
|
const error = derived(value, $v => validate($v, validators))
|
||||||
|
|
||||||
|
return [value, error]
|
||||||
|
}
|
||||||
|
|
||||||
|
function validate(value, validators) {
|
||||||
|
const failing = validators.find(v => v(value) !== true)
|
||||||
|
|
||||||
|
return failing && failing(value)
|
||||||
|
}
|
12
packages/builder/src/helpers/validation/validators.js
Normal file
12
packages/builder/src/helpers/validation/validators.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
function emailValidator (value) {
|
||||||
|
return (value && !!value.match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/)) || 'Please enter a valid email'
|
||||||
|
}
|
||||||
|
|
||||||
|
function requiredValidator (value) {
|
||||||
|
return (value !== undefined && value !== null && value !== '') || 'This field is required'
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
emailValidator,
|
||||||
|
requiredValidator
|
||||||
|
}
|
Loading…
Reference in a new issue