字母数字验证不工作在jquery [英] alphanumeric validation not working in jquery

查看:157
本文介绍了字母数字验证不工作在jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下,包含所有必需的js文件。

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');

?>

当我提交表单时没有给UserDetailAliasName赋值,表单不提交,验证错误信息是显示(此字段为必填),但如果我提交一个像@,#等值,表单提交数据。 iam使用此表单从db搜索用户名。

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)

这篇关于字母数字验证不工作在jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆