是否有用于英国地址或电话号码验证的伪代码?

发布于 2024-07-08 07:27:07 字数 142 浏览 9 评论 0原文

您是否有用于在英国现场验证以下项目的伪代码? 我来自美国,所以我现在只知道美国的。

  • 地址行 1
  • 电话号码
  • 手机号码(如果他们对此有特殊规则,但他们可能没有)
  • 邮政编码

Do you have pseudocode for field validation of the following items in the UK? I am from the USA, so I only know the ones in the USA right now.

  • Address Line 1
  • Phone Number
  • Mobile Number (in case they have a special rule for this, which they might not)
  • Post Code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

心作怪 2024-07-15 07:27:08

地址行 1,如果您想验证用户自由输入的内容,您可能会被淘汰。 存在巨大的可变性。 您可以使用邮政编码地址文件(见下文)来提供帮助,

通常,如果您想要一个“标准”地址,面向英国的网站会要求提供邮政编码,然后提示用户从该邮政编码的所有地址中选择正确的

地址和手机号码。 请参阅此处http://en.wikipedia.org/wiki/Telephone_numbers_in_the_United_Kingdom。 可以在此处找到验证这些的脚本(多种语言): http://www .braemoor.co.uk/software/telnumbers.shtml

邮政编码格式:http:// en.wikipedia.org/wiki/UK_postcodes(包含用于验证的正则表达式,并指列出有效地址的邮政编码地址文件)

Address line 1, if you want to validate what the user entered freeform, you're probably hosed. There's huge variability. You can use the PostCode Address File (see below) to assist,

Typically, if you want a "standard" address, UK-oriented websites ask for the postcode, then prompt the user to choose the correct address from all addresses at that postcode

Phone and mobile numbers. See here http://en.wikipedia.org/wiki/Telephone_numbers_in_the_United_Kingdom. A script to validate these (in several languages) can be found here: http://www.braemoor.co.uk/software/telnumbers.shtml

Post code format: http://en.wikipedia.org/wiki/UK_postcodes (contains a regular expression for validation, and refers to the Postcode Address File which lists valid addresses)

流云如水 2024-07-15 07:27:08

地址行 1 几乎可以是任何内容。 并不总是有门牌号码。

电话号码:区号的长度各不相同。 我不想发誓全长是否恒定,但我怀疑它总是至少 10 位数字。 手机号码 (IME) 通常以 07 开头,而固定电话通常以 01 或 02 开头。特殊号码(免费、本地费率等)通常以 08 开头。我将尝试找到这方面的参考。 (编辑:再说一次,有一篇很好的维基百科文章。)

维基百科有一个关于英国邮政编码的好文章,包括它们的正则表达式。

Address line 1 could be almost anything. There aren't always house numbers.

Phone numbers: the length of an area code varies. I wouldn't like to swear whether the full length is constant, but I suspect it's always at least 10 digits. Mobile numbers typically (IME) start with 07 whereas landlines typeically start with 01 or 02. Special numbers (free, local rate etc) typically start with 08. I'll try to find a reference for this. (EDIT: Again, there's a good Wikipedia article.)

Wikipedia has a good article about UK postcodes, including regular expressions for them.

夕色琉璃 2024-07-15 07:27:08

Perl 有 Number::Phone 模块,可以处理英国电话号码。 皇家邮政提供地址验证和列表清理服务。

Perl has the Number::Phone module that can handle UK phone numbers. Royal Mail has services for address validation and list cleansing.

我要还你自由 2024-07-15 07:27:08

对于英国电话号码,您最好的选择(不幸的是)可能是从 Ofcom 下载编号计划(它们是 Excel 电子表格,包含所有相关的号码范围,分为区号、“地理号码”、个人号码、手机号码、各种服务号码、不同的付费号码以及从号码范围到运营商的映射(尽管后者可能不是您需要的)。

For UK phone numbers, your best bet (unfortunately) is probably to download the numbering plans from Ofcom (they're excel spreadsheets, with all relevant number ranges, split up into area codes, "geographical numbers", personal numbers, mobile numbers, assorted service numbers, the different pay-for numbers and also have a mapping from number range to operator (the latter is probably NOT something you need, though).

灯下孤影 2024-07-15 07:27:08

与此类问题一样,不要沉迷于过度验证。 检查最有可能严重畸形的输入,然后继续。 尝试跟踪在任何特定区域设置中使用的电话号码的前缀和长度会极大地浪费您的时间。 允许一些可能可以修复的错误通过,比告诉他们“无效”而失去客户要好。

(在英国最接近标准的地址格式是邮政编码加门牌号。即便如此,总有例外。)

As always with this sort of question, don't get hung up on over-validation. Check for the most likely grossly-malformed inputs then move on. Trying to keep track of what prefixes and lengths of phone number are in use in any particular locale is an enormous waste of your time. Letting a few, possibly-fixable mistakes through is better than losing customers by telling them they are ‘invalid’.

(The nearest to a standard addressing format you get in the UK is postcode plus house number. Even then there are always exceptions. )

梦途 2024-07-15 07:27:08

我已经开始编写用于 Django 表单验证 GB 电话号码的代码(或至少一堆正则表达式模式) 这里
此处有基本说明。

I've started the code (or at least a bunch of RegEx patterns) for Django forms validation for GB telephone numbers here.
With a basic explanation here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文