adds missing files

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-11 17:51:19 +02:00
parent e8d8bb67ee
commit b10c41143f
2 changed files with 27 additions and 0 deletions

View 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)
}

View 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
}