Blazing fast Javascript validation library
<script src="https://github.com/C-Lodder/validatejs-es6/raw/master/validate.min.js"></script>
or import it:
import Validator from "./validate.min.js"
Should you require support for Internet Explorer, use validate-es5.min.js
intead
<input type="text" id="name">
const Validation = new Validator({
rules: {
// Ensure the property matches that of the input ID
name: {
required: true,
},
},
messages: {
name: {
required: 'Please enter your name',
},
},
errorPlacement: (error, element) => {
alert(error);
// You can append the error to an element below the input or anything else to your liking
}
});
const isValid = Validation.validate(document.getElementById('name'));
// Returns true or false