Background
The
jQuery.mbValidation Plugin is an excellent tool for web pages to validate data entries at the client side using JavaScript. It is very easy to integrate this plugin into your web application and do many validations on web forms.
This is an Open Source project I have begun on Github for easy web application development, to simplify web page validations and to get maximum output with less coding.Validation Properties
- ForceOnlyNumeric: This property used to allow only numbers or numeric values in input field.
- ForceOnlyAlpha: This property used to allow only alphabets or numeric values in input field.
- ForceOnlyAlphaNumeric: This property used to allow only alphabets and numbers or alpha/numeric values in input field.
- MaxLength(Number): This property used to restrict maximum length of value in input field.
- ForceAmount: This property used to validate amount values in input field.
- ForceEmail: This property used to validate Email Id in input field.
- ForceContactNumber: This property used to validate contact number in input field.
- MinLength(Number): This property used to validate minimum length in input field.
- ForceURL: This property used to validate URL in input field.
Code
The structure of the attached Microsoft Visual Studio 2012 solution is as follows:
The
jQuery.mbValidation Plugin relies on jQuery plugin to work, so I included the
jquery-1.10.2.js file in the Scripts folder. You can also use the Compressed jQuery file that is
jquery.min.js. I have added
jquery-ui.css for the demo page and
mb-ui.css that is required for the jQuery.mbValidatioin plugin.
Here is the structure of the
mb-ui.css file.
You can customize the jQuery.mbValidation plugin error message by modifying this CSS file.
- body {
- font: 62.5% "Trebuchet MS", sans-serif;
- }
- .custom-error {
- z-index: 1000;
- position: absolute;
- background-color: white;
- color: red;
- border: 1px solid gray;
- padding: 3px;
- font: 62.5% "Trebuchet MS", sans-serif;
- border-radius: 5px;
- -moz-border-radius: 5px;
- -webkit-border-radius: 5px;
- font-size: 1.1em;
- font-family: Verdana,Arial,sans-serif;
- }
The following is the demo page that is the index.html file:
For required field validation specify
class="required" for input and call
PerformValidations() on the button's onClick event.
- <input type="text" id="txtDemoField1" class="required" />
- <button id="btnValidate" type="button" onClick="PerformValidations();">Validate</button>
Contribute
To contribute
FORK jQuery.mbValidatioin Plugin on Github.