开发者

alphanumeric validation not working in jquery

my code is given below,all the required js files are included.

<?php 
    echo $this->Html->script('jquery');
    echo $this->Html开发者_运维问答->script('jquery-ui');
    echo $this->Html->script('jquery.validate');
    echo $html->css('jquery-ui');

?>

when i submit the form without giving any value for UserDetailAliasName the form does not submits and validation error message is displayed("this field is required").but if i submit a value like @,# etc the form submits the data. iam using this form to search for username from db.

$(document).ready(function () {
    jQuery.validator.addMethod("alphaNumeric", function (value, element) {
        return this.optional(element) || /^[0-9a-zA-Z]+$/.test(value);
    }, "Username must contain only letters, numbers.");


    $('#UserDetailIndexForm').validate({
        rules: {
            UserDetailAliasName: {
                required: true,
                alphaNumeric: true
            }
        }
    });

});


Include a message below rules too:

    messages: {
    account:{
        required:"Porfavor ingresa tu ID de cuenta",
        minlength:"La cuenta debe tener al menos 6 caracteres",
        alphanumeric:"No se permite que ingreses caracteres invalidos"
    }

that work for me (my local language is spanish)


tested and that works.. is required also not working for you?

demo


            if ($('#element').val() != "value") {
            var a = e.key;
            if (a.length == 1) return /[a-z]|[0-9]|&/i.test(a);
            return true;
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜