简体   繁体   English

荷兰银行账户验证规则

[英]dutch Bank account validation rule

Can anybody advise me how to make a validation rule for Dutch bank accounts?谁能告诉我如何为荷兰银行账户制定验证规则?

So far i could only found this on web:到目前为止,我只能在 web 上找到这个:

regex = /[0-9]{2}[\\s]{1}[0-9]{2}[\\s]{1}[0-9]{2}[\\s]{1}[0-9]{3}/;

This is my JavaScript:这是我的 JavaScript:

function dutchBankAccount(input) {
var regex = /[0-9]{2}[\\s]{1}[0-9]{2}[\\s]{1}[0-9]{2}[\\s]{1}[0-9]{3}/;
if(input.value.toString().match(regex) && !(input.value == "")) {
    return true;
} else {
    input.click();
    input.style.border = '2px solid #F20056';
    return false;
}

}

And here is my HTML code:这是我的 HTML 代码:

<li><input type="text" id="anum" placeholder="Account Number" autocomplete="off" onkeypress="return isNumberKey(event)" onBlur="isValidAnum()" onFocus="emptyAnum('anum')"/></li>

Later on when I enter a dutch bank account I get error which I'm not supposed to get.后来当我输入一个荷兰银行账户时,我得到了我不应该得到的错误。 So if you know how to solve this please help me.所以如果你知道如何解决这个问题,请帮助我。

The regex syntax is incorrect.正则表达式语法不正确。 Try something more like this:尝试更多类似的东西:

var regex = /[0-9]{2}\s[0-9]{2}\s[0-9]{2}\s[0-9]{3}/;

That matches strings like匹配字符串,如

32 01 28 192

Two digits followed by a space three times, then three digits.两个数字后跟一个空格三次,然后是三个数字。 Whether that's what all Dutch bank accounts look like I don't know, though that seems like a small namespace for something like that.我不知道这是否是所有荷兰银行账户的样子,尽管这似乎是一个类似的小名称空间。

(It occurs to me that /(?:\d{2}\s){3}\d{3}/ should match the same strings and it's a little shorter.) (我突然想到/(?:\d{2}\s){3}\d{3}/应该匹配相同的字符串,而且要短一些。)

edit — To elaborate, the regex in the original code has some problems:编辑——详细地说,原始代码中的正则表达式存在一些问题:

  • The backslashe before each of the "\s" (space) characters is doubled, but it should not be.每个“\s”(空格)字符前的反斜杠加倍,但不应该加倍。 (That's assuming that Dutch bank account numbers don't actually look like "92\s31\28s\120") (假设荷兰银行帐号实际上并不像“92\s31\28s\120”)
  • Putting a single character class shortcut ("\s") in square brackets is needlessly redundant将单个字符 class 快捷方式(“\s”)放在方括号中是不必要的冗余
  • Suffixing a regex element with "{1}" is needlessly redundant too使用“{1}”为正则表达式元素添加后缀也是不必要的冗余

The real problem was the extra backslash.真正的问题是额外的反斜杠。 Also, speaking of needlessly redundant, there's no need to call ".toString()" on the value of an input element "value" attribute, and there's no need to make sure the value isn't the empty string if it has matched the pattern.另外,说到不必要的冗余,没有必要对输入元素“value”属性的值调用“.toString()”,也没有必要确保该值不是空字符串,如果它匹配图案。 In this case, an empty string cannot match the pattern, so that test is not necessary.在这种情况下,空字符串无法匹配模式,因此不需要进行测试。 Finally (promise), if you're just testing a regex against a string, the ".test()" method on the RegExp prototype is a little more efficient:最后(承诺),如果您只是针对字符串测试正则表达式,则 RegExp 原型上的“.test()”方法效率更高:

if (regex.test(input.value)) { // matched
  // ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM