首页 > 代码库 > jQuery validation 去除空格
jQuery validation 去除空格
当input输入了空格是不会提示信息的
一般会去除空格然后进行验证
这个时候就要添加onkeyup事件去除左侧的空格
//添加验证手机方法 jQuery.validator.addMethod("isMobile", function(value, element) { var length = value.length; var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/; return this.optional(element) || (length == 11 && mobile.test(value)); }, "请正确填写您的手机号码"); //表单验证 $("#enterpriseAuth").validate({ debug: true, onkeyup: function(element, event) { //去除左侧空格 var value = http://www.mamicode.com/this.elementValue(element).replace(/^/s+/g,""); $(element).val(value); }, errorClass: ‘errMsg‘, errorElement: "div", errorPlacement: function(error, element) { error.appendTo(element.parent()); }, groups: { distpicker: "province city district" }, rules: { enterpriseName: { required: true }, managerPhone: "isMobile", managerEmail: { email: true, }, province: "required", city: "required", district: "required" }, messages: { enterpriseName: { required: "请填写企业名称", }, enterpriseAddress: { required: "请填写公司注册地址", }, enterpriseContact: { required: "请填写街道详细地址", }, managerName: { required: "请填写管理者姓名", }, managerEmail: { required: "请填写管理者邮箱", email: "请填写正确邮箱格式" }, managerPhone: { required: "请输入手机号", isMobile: "请填写正确手机号" }, province: { required: "请选择省市区", }, city: { required: "请选择省市区", }, district: { required: "请选择省市区", } } });
jQuery validation 去除空格
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。