Minimal HTML5 Form Validation Library – okjs

Category: Form , Javascript | September 21, 2018
Views Total:1,906 views
Official Page:Go to website
Last Update:September 21, 2018


Minimal HTML5 Form Validation Library – okjs


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.

  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">


v3.4.0 (09/21/2018)

  • feat: Added support for legacy browsers not supporting the validation API

You Might Be Interested In:

Leave a Reply