Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.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 如何使用BackboneJS禁止PAN编号中的特殊字符_Javascript_Backbone.js - Fatal编程技术网

Javascript 如何使用BackboneJS禁止PAN编号中的特殊字符

Javascript 如何使用BackboneJS禁止PAN编号中的特殊字符,javascript,backbone.js,Javascript,Backbone.js,我正在尝试添加PAN编号验证以禁止特殊字符,但我的代码如下所示无法按预期工作: if (attributes.isOwnProfile && attributes.totalExperience > 0 && $.trim(attributes.panNumber) == "") { errors.push({ key: "panNo", message: "Required" }); } el

我正在尝试添加PAN编号验证以禁止特殊字符,但我的代码如下所示无法按预期工作:

if (attributes.isOwnProfile &&
    attributes.totalExperience > 0 &&
    $.trim(attributes.panNumber) == "") {
    errors.push({
        key: "panNo",
        message: "Required"
    });
} else if ($.trim(attributes.panNumber) != "" &&
    attributes.panNumber.length !== 10) {
    errors.push({
        key: "panNo",
        message: "Not a valid PAN No"
    });
} else if (!(/[^a-zA-Z0-9]/).test(attributes.panNumber)) {
    errors.push({
        key: "panNo",
        message: "Not a valid PAN No"
    });
}

您的正则表达式正在检查是否存在任何特殊字符,若存在,它将返回true,您将使用
对其求反运算符,因此存在特殊字符时不满足条件

您应该删除

else if((/[^a-zA-Z0-9]/).test(attributes.panNumber)) {
   errors.push({
      key: "panNo",
      message: "Not a valid PAN No"
      });
}

没有错误。。它还具有可接受性。Regx/[^a-zA-Z0-9]/不工作。此代码是模型的一部分吗?它被处决了吗?粘贴完整的代码是的,它是模型的一部分,长度验证工作正常,只有regx部分