标签:
/*编写时间:2015-6-4*/ (function ($) { $.fn.isValidate = function (obj) { if ($(this).val()!="") { var txt = $(this).val(); //表单元素:input } var reg; switch (obj) { case 0: reg = /-?\\d+/;/*匹配整数*/ return reg.test(txt); case 1: reg = /^\d+(\.\d+)?$/; /*匹配非负浮点数*/ return reg.test(txt); case 2: reg = /^(-?\d+)(\.\d+)?$/;/*匹配浮点数*/ return reg.test(txt); case 3: reg = /^[A-Za-z]+$/;/*匹配26个英文字母*/ return reg.test(txt); case 4: reg = /[\u4e00-\u9fa5]/;/*匹配中文字符*/ return reg.test(txt); case 5: reg = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;/*匹配Email地址*/ return reg.test(txt); case 6: reg = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\‘:+!]*([^<>\"\"])*$/;/*匹配网址URL*/ return reg.test(txt); case 7: reg = /^(13[0-9]{9})|(18[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;/*匹配手机号码*/ return reg.test(txt); case 8: reg = /(100|([1-9]?[0-9]?))%/;/*匹配百分数*/ return reg.test(txt); case 9: reg = /^\w+$/;/*匹配由数字、26个英文字母或者下划线组成的字符串*/ return reg.test(txt); case 10: reg = /^[0-9]*[1-9][0-9]*$/;/*匹配大于0整数*/ return reg.test(txt); case 11: reg = /^([0-1][0-9]|[2][0-3]):([0-5][0-9])$/;/*匹配时间*/ return reg.test(txt); case 12: reg = /(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)/;/*匹配日期*/ return reg.test(txt); case 13: reg = /^[1-9]\d{0,3}$/;/*匹配大于0的四位整数*/ return reg.test(txt); case 14: reg = /^[0-9]\d{0,7}(\.\d{1,2})?$/;/*匹配2位小数及大于0的8位整数*/ return reg.test(txt); case 15: reg = /^[1-9]\d{0,8}$/;/*匹配大于0的9位整数*/ return reg.test(txt); case 16: reg = /&+/;/*匹配&符号*/ return reg.test(txt); case 17: reg = /^[1-9]\d{0,4}$/;/*匹配大于0的5位整数*/ return reg.test(txt); case 18: reg = /^[0-9]\d{0,1}(\.\d{1,4})?$/;/*匹配2位小数*/ return reg.test(txt); case 19: reg = /^[1-9]\d*$/;/*匹配正整数*/ return reg.test(txt); case 21: reg = /^(\d{14}|\d{17})(\d|[xX])$/;/*匹配身份证*/ return reg.test(txt); default: return false; } } })(jQuery)
标签:
原文地址:http://www.cnblogs.com/wanliyuan/p/4597483.html