Native JavaScript Form Validator for Bootstrap 4, pure JavasSript solution without jQuery. Sample can be found here
Install via NPM:
npm install iskandarjamil/native-validator-bootstrap
import Validator from "native-validator-bootstrap";
new Validator("form");
// or
new Valudator("form", {
// options
});
Feel free to add customization, can follow sample like below.
Add data-pluginname
and data-pluginname-error
for error message.
<input type="text" data-numberonly data-numberonly-error="Accept number only." />
import Validator from "native-validator-bootstrap";
Validator.plugin("numberonly", {
// Optional if want to run something once the Validator created.
install(el) {},
// Required, return True/False
validate(el, attribute) {
return /^\d+$/.test(el.value);
},
// Optional Error message can be define here.
error(el) {},
});
var validator = new Validator(document.querySelector("form"));
Type | Description | Default |
---|---|---|
showValid | Enable/Disable success input response | True |
autoScroll | Enable/Disable auto scrolling to first error | True |
delay | Timer delay start checking validation after blur event | 500 (ms) |
offsetFocus | Offset scrolling for autoScroll | 50 (ms) |
Type | Description | Rules |
---|---|---|
match | Check equal value between two input, example password match | data-match |
Safe email validation | data-email |
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
MIT license.