@datametria/vue-components
Version:
DATAMETRIA Vue.js 3 Component Library with Multi-Brand Theming - 51 components + 10 composables with theming support, WCAG 2.2 AA, dark mode, responsive system
40 lines (33 loc) • 866 B
text/typescript
// Simple validators that return boolean
export const required = (value: any): boolean => {
return !!value
}
export const email = (value: any): boolean => {
if (!value) return true
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)
}
export const minLength = (min: number) => (value: any): boolean => {
if (!value) return true
return value.length >= min
}
export const maxLength = (max: number) => (value: any): boolean => {
if (!value) return true
return value.length <= max
}
export const pattern = (regex: RegExp) => (value: any): boolean => {
if (!value) return true
return regex.test(value)
}
export const custom = (validator: (value: any) => boolean) => (value: any): boolean => {
return validator(value)
}
export function useValidation() {
return {
required,
email,
minLength,
maxLength,
pattern,
custom
}
}