ui-lib/lib/ui/extension.js
2024-01-17 17:31:41 +08:00

12 lines
406 B
JavaScript

export function validation(element, regex) {
if (element instanceof HTMLElement && regex instanceof RegExp) {
element.addEventListener('change', e => {
if (regex.test(e.target.value)) {
e.target.classList.remove('validation-error');
} else {
e.target.classList.add('validation-error');
}
})
}
return element;
}