gpt4 book ai didi

javascript - 类型错误 : Unable to get value of the property 'test' : object is null or undefinedundefined

转载 作者:行者123 更新时间:2023-11-27 23:44:19 26 4
gpt4 key购买 nike

我有一个通过一组正则表达式计算字符串的函数。这些正则表达式作为它们自己的对象包装在 charRules 中。

如果字符串无效,则返回 false,否则返回 true。

有效字符串示例:1234567890123K

无效字符串示例:!@#$%^&*!!!&H5

当用户在文本输入中键入其值时,IE8 会在控制台中抛出错误,

TypeError: Unable to get value of the property 'test': object is null or undefinedundefined

IE9+、Chrome、Firefox、Safari 按预期工作。

逻辑作为指令实现。这是附加到作用域的核心逻辑,

                    scope.validate = function(value) {

// Letters and special characters not allowed per country.
var charRules = {
br: {
haveLetters: /[a-zA-Z]/,
haveSpecials: /[!@$%^&*()_+|~=`\\#{}\[\]:";'<>?,]/,
minMaxLength: /^.{12,25}$/
},
cl: {
haveLetters: /[a-jl-zA-JL-Z]/,
haveSpecials: /[!@$%^&*()_+|~=`\\#{}\[\]:";'<>?,\/]/,
minMaxLength: /^.{12,25}$/
},
mx: {
haveLetters: /[]/,
haveSpecials: /[!@$%^&*()_+|~=`\\#{}\[\]:";'<>?,\/.-]/,
minMaxLength: /^.{12,25}$/
},
pr: {
haveLetters: /[a-zA-Z]/,
haveSpecials: /[!@$%^&*()_+|~=`\\#{}\[\]:";'<>?,\/.]/,
minMaxLength: /^.{12,25}$/
}
};

if (charRules[country]) {
if (charRules[country].haveLetters.test(value) || charRules[country].haveSpecials.test(value) || !charRules[country].minMaxLength.test(value)) {
return false;
} else {
return true;
}
}
};

country 变量是全局定义的。适用于 HTML 的指令是 rut="mx"

它适用于此 HTML,

<input type="text" id="address_rut" rut="mx" class="input-xlarge" ng-switch-when="mx" ng-model="rutnumber.taxIDNumber" ng-show="editing" required>

对于导致字符串值仅在 IE8 中无法解释的任何想法?

最佳答案

Internet Explorer 8 抛出:

Expected ']' in regular expression

当尝试在正则表达式中使用空括号时。

    /[]/

您应该尝试更具体地描述您不想在其中匹配的字符类似的,根据您的需要,您可能需要添加更多排除条件:

/[^\w^\w]/

关于javascript - 类型错误 : Unable to get value of the property 'test' : object is null or undefinedundefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33377113/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com