gpt4 book ai didi

php - BIC 检查的正则表达式

转载 作者:可可西里 更新时间:2023-10-31 22:08:33 27 4
gpt4 key购买 nike

我为 php 函数 pregmatch 写了一个正则表达式,如下所示:

^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$^

现在我需要检查 BIC 字符串的一致性。

它有问题……它总是正确的。我不知道为什么。

我使用的代码是这样的:

/**
* Checks the correct format from the
* @param string $bic
* @return boolean
*/
public function checkBic($bic)
{
$bic = $this->cleanFromSeparators($bic);
if (preg_match($this->getBicCompare(), $bic)) {
return true;
} else {
return false;
}
}

private function getBicCompare()
{
return "^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$^";
}

编辑:

以下是swift账户中BIC格式的一些引用资料:

http://www.sage.co.uk/sage1000v2_1/form_help/workingw/subfiles/iban_and_bic.htm

http://en.wikipedia.org/wiki/ISO_9362

http://www.swift.com/products_services/bic_and_iban_format_registration_bic_details?rdct=t

一个示例 BIC 是:

NOLADE21STS

OPSKATWW

只有当字符串包含以下代码时,正则表达式才应返回 true:它的长度是八个或十一个字符,包括:

银行代码 - 4 个字母字符国家代码 - 2 个字母位置代码 - 2 个字母数字字符,零除外分行代码 - 3 个字母数字字符

这些是规范。

所以长度可以是 11 或 8,前 4 可以是任何东西,然后 2 个字母是必须的,然后是 2 个数字和可选的 3 个字母数字。

以下内容无效:

abcdefxx

abcdefxxyyy

这些也是无效的:

aaaa11xx

aaaa11xxyyy

等等。

最佳答案

您正在使用 ^ 作为分隔符吗?你可能想要更像的东西:

'/^[a-z]{6}[0-9a-z]{2}([0-9a-z]{3})?\z/i'

关于php - BIC 检查的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15920008/

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