jquery表单验证不允许用户名字段的空间?

前端之家收集整理的这篇文章主要介绍了jquery表单验证不允许用户名字段的空间?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经用了 http://bassistance.de/jquery-plugins/jquery-plugin-validation/

我的表单验证:

$("#form_person").validate({
    rules: {


        username: {
            required: true,minlength: 2,maxlength:15
        },password: {
            required: true,minlength: 2
        },confirm_password: {
            required: true,equalTo: "#password"
        },email: {
            required: true,email: true
        }

    },messages: {

        username: {
            required: "Please enter a username",maxlength:"max length 15 digits",minlength: "Your username must consist of at least 2 characters"
        },password: {
            required: "Please provide a password",minlength: "Your password must be at least 5 characters long"
        },confirm_password: {
            required: "Please provide a confirm password",minlength: "Your password must be at least 5 characters long",equalTo: "Please enter the same password as above"

    }
});

任何人帮我验证不允许用户名空间?

谢谢

解决方法

你可以尝试这样的:
$(document).ready(function(){

  jQuery.validator.addMethod("noSpace",function(value,element) { 
  return value.indexOf(" ") < 0 && value != ""; 
},"No space please and don't leave it empty");


$("form").validate({
   rules: {
      name: {
          noSpace: true
      }
   }
  });


})

quick demo
more on addMethod here
and an example also here.

猜你在找的jQuery相关文章