
okjs is a JavaScript library used to extend the HTML5 form validation api that supports custom field validation rules & error messages. Without any 3rd dependencies.
How to use it:
Load the main JavaScript file ok.js when needed.
<script src="ok.js"></script>
Initialize the form validation library and add your own validation rules and error messages.
Ok({
el: "form",
validators: {
nameCaps: {
msg: "Please input your name in caps",
fn: val => {
return /[A-Z ]+/.test(val);
}
},
emailDe: {
msg: "Please input your .com email",
fn: val => {
return val.endsWith(".com");
}
}
}
});Apply the validation rules to the form fields using HTML data attributes as shown below:
<input type="text" placeholder="Enter Name" required data-ok="nameCaps"> <input type="email" placeholder="Enter email" required data-ok="emailDe">
Changelog:
v3.4.0 (09/21/2018)
- feat: Added support for legacy browsers not supporting the validation API







