adds missing files
This commit is contained in:
parent
e8d8bb67ee
commit
b10c41143f
|
@ -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)
|
||||
}
|
|
@ -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 New Issue