JQuery implementation of global validation under Bootstrapvalidator

Source: Internet
Author: User

Front-facing:

Introduction of jquery, Bootstrap, Bootstrapvalidator

Problem Description:

The & symbol is not required for all form input boxes in the project. There is no way to find a method available in bootstrap, you can do it yourself.

Ideas:

Use the regular.

In two cases, the first, if the input box has its own regular validation is not to go to the tube (generally using regular validation is strictly controlled input), and the second, if there is no regular, you need to add a regular that cannot enter &.

You need to overload the Bootstrapvalidator initialization function to fix the initialized settings based on the two scenarios above. Finally to restore the original Bootstrapvalidator function (this step is necessary, the original Bootstrapvalidator function has its own a large pile of related east, can not be lost);

Realize:

/*Add chenhua 2015.10.16 rewrite the Bootstrapvalidator method? Add a prohibit input "&" symbol to each validation entry*/$ (function () {
//Save the original Bootstrapvalidator varOverwrite =$.fn.bootstrapvalidator;
//Heavy Duty bootstrapvalidator $.fn.bootstrapvalidator=function (options) {//Restore the originalBootstrapvalidator, because it adds a lot of data that can't be lost.$.fn.bootstrapvalidator =overwrite;
Here are two approaches, the first is to directly modify the arguments content, so that it contains no input & validation, and then call it;
The second is to use arguments to initialize and then use the function that calls Bootstrapvalidator to add validation that cannot be entered & for items that are not regular expression validation
//Here we used the second.  varValidtor = Overwrite.apply ( This, arguments); if($.type (arguments[0]) =="Object"){ varVtor = This. Data ("Bootstrapvalidator"),
//filter out the Input box form item fileds= This. Find ("input[name][type= ' hidden '],input[name][type= ' password '],input[name][type= ' text '],textarea[name]"). Not (":d isabled,[type= ' hidden ']"); Fileds.each (function () {//No validation is added that cannot be entered & by itself without regular validationif(!vtor.getoptions ($ ( This). attr ('name'),'RegExp','RegExp') {Vtor.addfield ($ ( This). attr ('name'{validators: {regexp: { regexp:/^[^&]*$/, message:"cannot contain & characters"}})} ) }returnValidtor; } })

  

JQuery implementation of global validation under Bootstrapvalidator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.