Skip to content

Small, fast and flexible Javascript validation library

Notifications You must be signed in to change notification settings

C-Lodder/validatejs-es6

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ValidateJS-ES6

Blazing fast Javascript validation library

Usage

Include the validation script on your page:

<script src="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

Create a simple input field:

<input type="text" id="name">

Basic usage:

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
	}
});

Validate an element

const isValid = Validation.validate(document.getElementById('name'));

// Returns true or false

About

Small, fast and flexible Javascript validation library

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published