Universal Form Validation Plug-in

Source: Internet
Author: User

$ (function () {$ ("[Reg]"). KeyUp (function () {var reg = $ (this) [0].getattribute ("Reg"); eval ("Reg =" +reg); var value = $ ( This) [0].value;//gets whether the prompt box is showing var isshow = $ (this) [0].getattribute ("isshow"); var regexp = new RegExp (reg);//Regular  mismatch The prompt box does not display if (!regexp.test (value) && (isshow=== "false" | | isshow===null)) {$ (this). PopOver (' show '); $ (this) [0]. SetAttribute ("Isshow", "true");} else if (regexp.test (value)) {$ (this) [0].setattribute ("Isshow", "false"); $ (this). PopOver (' hide ');});}); $ (function () {$ (". Checkall"). Submit (function () {var regs = $ (this). Find ("[Reg]"), for (var i=0; i<regs.length; i++) { var reg = Regs[i].getattribute ("Reg"), eval ("reg=" +reg), var value = regs[i].value;if (!reg.test (value)) {$ (regs[i]). PopOver (' show '), if (regs.length-1 = = i) {alert ("data not filled in correctly"); return false;}}});});

<div class= "Form-group" >
<label for= "InputPassword3" class= "col-sm-4 Control-label" > Phone number </label>
<div class= "Col-sm-8" >
<input data-container= "Body" data-toggle= "popover" data-placement= "right"
data-content= "<p> Please enter the correct phone number </p>"
Data-html= "true" data-trigger= "manual"
Reg= "/^1 ([38]\d|4[57]|5[0-35-9]|7[06-8]|8[89]) \d{8}$/"
Type= "text" name= "PhoneNumber" class= "Form-control" id= "InputPassword3" placeholder= "phone number" >
</div>
</div>

Because Bootstrap's inspiration wrote a generic validation (just fill in the form with a reg). Have not looked for similar plugins, detailed steps to write tomorrow. Bootstrap has a bug, etc. modified the source code will be submitted

Universal Form Validation Plug-in

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.