Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery验证-检查字符串是否包含unicode或空格字符';行不通_Javascript_Jquery_Jquery Validate - Fatal编程技术网

Javascript jQuery验证-检查字符串是否包含unicode或空格字符';行不通

Javascript jQuery验证-检查字符串是否包含unicode或空格字符';行不通,javascript,jquery,jquery-validate,Javascript,Jquery,Jquery Validate,请查看我的代码,checkUser函数不起作用。我认为value.match()函数中有错误: <form id="register_form" method="post" action=""> <fieldset> <legend>Info</legend> <div> <label>Username</label> &l

请查看我的代码,checkUser函数不起作用。我认为value.match()函数中有错误:

<form id="register_form" method="post" action="">
    <fieldset>
        <legend>Info</legend>

        <div>
            <label>Username</label>
            <input type="text" name="username" id="username"/>
            <input type="submit" id="btnAccess" class="button" value="Submit" name="btnAccess"/>
    </fieldset>
</form>
你可以在这里查看

试试看

jQuery(function ($) {
    var validator = $('#register_form').validate({
        rules: {
            username: {
                required: true,
                minlength: 4,
                checkUsername: true
            }
        },
        messages: {
            username: {
                required: "No blank",
                minlength: "Enter atleast 4 words"
            }
        }
    });

    $.validator.addMethod('checkUsername', function(value, element) {
        return this.optional(element) || (!/\s/g.test(value) && !/[ÀÁÂÃÈÉÊÌÍÒÓÔÕÙ]/.test(value));
    },  "No space or unicode character");;
});
演示:

试试看

jQuery(function ($) {
    var validator = $('#register_form').validate({
        rules: {
            username: {
                required: true,
                minlength: 4,
                checkUsername: true
            }
        },
        messages: {
            username: {
                required: "No blank",
                minlength: "Enter atleast 4 words"
            }
        }
    });

    $.validator.addMethod('checkUsername', function(value, element) {
        return this.optional(element) || (!/\s/g.test(value) && !/[ÀÁÂÃÈÉÊÌÍÒÓÔÕÙ]/.test(value));
    },  "No space or unicode character");;
});
演示: