How To Provide Client Side Validation Using LIveValidation
Posted By : Sunny Srivastava | 18-Sep-2017
LiveValidation is a lightweight javascript library available across all major browsers. LiveValidation is a plugin written over javascript to save developer precious time by providing various functionality and features. LiveValidation allows the programmer to perform client side validation of input element with great ease.
Although LiveValidation provides great function to validate fields on the client side but they are not complete replacement for server side code.
How To use?
LiveValidation plugin is very easy to incorporate into project. All you have to do is just import the basic jquery plugin and live validation plugin to your code. And create an input element and add the validation class to validate it during run time.
Steps to integrate LiveValidation plugin into your code :
1. First import the required file.
<script src="https://code.jquery.com/jquery-2.2.4.js" ></script>
<script src="/script/livevalidation.js" ></script>
2. Create an input element you want to validate
<form id="validationModule" name="validationModule" action="/validate/validation.php" >
<input type="password" name ="passwordField" id="passwordField" class="LV_valid_field" >
</form>
3. Create validation object
var validateField = new LiveValidation('passwordField',{validMessage :"valid!"};
4. When we have validation object we can use the add method to use valious suitable method. Livevalidation has various method to perform validation. For say we are using length as a factor to perform validation.
validateField.add(Validate.length, {minimum:6, maximum:10});
Various LiveValidation Methods :
Presence
This checks if an input is having the empty or null field.
validateField.add(Validate.Presence);
Format
This method lets you use regular expression to filter the type of data you can enter
validateField.add(Validate.Format,{pattern:"your pattern"});
Acceptance
This checks if a field has boolean value true
validateFiled.add(Validate.Acceptance);
This method checks for the valid email address entered by the user.
validateFiled.add(Validate.Email);
And this is it. We can use various options and methods available under LiveValidation to perform validation on client side according to our requirements.
Thanks.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Sunny Srivastava
Sunny is a bright Web App Developer, having good knowledge of Core java .