是否有适用于 Perl 的所有国家/地区电话号码验证器?

发布于 2024-07-15 07:39:01 字数 306 浏览 6 评论 0原文

我正在使用 Perl 进行 Web 开发。 我需要对所有国家/地区进行电话号码验证。 是否有开源 Perl 模块可以执行以下操作?

例如:国家=马来西亚,如果用户输入电话号码=+60127008007,验证后返回这是马来西亚的有效手机号码,其中: 在马来西亚当地,我们直接拨打:0127008007。 “+6”是国际代码。

而如果用户输入电话号码 = +600127008007,则返回无效电话号码。 因为在马来西亚本地,没有这样的号码:00127008007。

任何免费模块都可以做到这一点,在 CPAN 或其他方面?

I am doing web development with Perl. I need to do phone number validation for all countries. Is there open source Perl module that can do the following?

For example: country = Malaysia, if user input phone number = +60127008007, after validate, it return this is a valid mobile number in Malaysia, where:
In local Malaysia, we call: 0127008007 directly. "+6" is the international code.

Whereas if user input phone number = +600127008007, it returns as invalid phone number. Because locally in Malaysia, there is no such number as: 00127008007.

Any free module than can do this, in CPAN or otherwise?

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

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

发布评论

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

评论(7

逆流 2024-07-22 07:39:01

看看 Number::Phone::NANP (lNumber::Phone:: NANP)。
我想您将为未覆盖的国家/地区添加新的子类。

Have a look at Number::Phone::NANP (lNumber::Phone::NANP).
I guess you will add new sub classes for uncovered countries.

書生途 2024-07-22 07:39:01

验证假设您比输入数据的人了解更多,但在本例中您并不了解。 假设我是一名美国人,在加拿大签订长期合同。 我保留了我的手机,因为我工作的公司正在支付漫游费。 当我访问您的网站并输入我的美国手机号码和加拿大地址时,您的验证脚本声称它无效,但实际上并非如此。 这会导致客户困惑和愤怒。

如果您的企业绝对需要有效的电话号码(或与此相关的电子邮件),您必须致电(或发送电子邮件)该号码(或电子邮件地址)的人员,并让他们输入您提供的代码。 有一种硬件/软件旨在自动拨打号码并向收件人提供消息。 您可以使用 Festival 等文本转语音软件通过电话播放特殊键,然后让他们输入进入您的网站以确认他们可以访问该手机。 但即便如此,这也不是绝对正确的,因为我可以买一部废弃的手机或创建一个废弃的电子邮件地址。

Validation assumes you know more than the person entering the data, but in this case you do not. Let's say that I am an American working a long term contract in Canada. I have kept my cell phone because the company I am working for is paying the roaming charges. When I visit your site and enter my American cell phone number and Canadian address your validation script claims it is invalid when it is not. This leads to customer confusion and anger.

If a valid phone number (or email for that matter) is an absolute requirement for your business you must call (or email) the person at the number (or email address) and have them enter a code you give them. There is hardware/software designed to automatically call numbers and provide a message to the recipient. You could use text to speech software like Festival to play a special key over the phone and then have them type it into your website to confirm that they have access to that phone. Even this is not infallible though, as I could buy a throw away cell phone or create a throw away email address.

西瓜 2024-07-22 07:39:01

验证的目的是通过捕获输入错误来帮助用户,强制他们在输入过程中使用特定格式。

到了某个点,验证就不再对用户有帮助了。 通常,这也是验证规则的例外变得太多而程序员无法处理的点,因为他进入了收益递减的领域。

为什么需要经过验证的电话号码? 您确定用户不会尝试在同一字段中输入两个数字并沮丧地放弃吗? 您确定用户不会输入“555-5555(询问 Steve)”或“555-5555(分机 123)”或其他完全有效的输入? 您确定您足够聪明,可以预测用户可能需要在该字段中输入的每个输入吗?

不要试图智胜你的用户。 帮助他。 :)

The point of validation is to help user by catching input errors of forcing them to use specific format during input.

There is a point where validation stops being helpful to the user. Usually, this is also the point where exceptions to the validation rules become too much for programmer to handle, since he entered the land of diminishing returns.

Why do you need validated phone number? Are you sure user won't try to enter two number in the same field and give up in frustration? Are you sure user won't enter something like "555-5555 (ask for Steve)" or "555-5555 (extension 123)" or some other totally valid input? Are you sure you're smart enough to predict every input user might need to enter in that field?

Don't try to outsmart your user. Help him. :)

心凉 2024-07-22 07:39:01

实际上不可能保留每个国家/地区的有效区号和号码长度的最新列表。

我建议您检查以下内容:

  1. 国际电话代码(1 至 3 位数字)
  2. 区号(通常为 3 位数字,但范围为 1 至 5 位数字)
  3. 电话号码(通常为 6 至 8 位数字,但范围为 4 至 13 位数字) )

所以你有 6 到 21 位数字,特别感谢奥地利。 =)

话虽这么说,除非您拨打该号码,否则您永远无法确定该电话号码是否有效。 您将让人们以自己的方式进行验证(例如,通过输入不属于他们的有效公共号码),因此您应该问自己:“这真的有必要吗?”

It's practically impossible to keep an up-to-date list of valid area codes and number lengths for each country.

I suggest you check for this:

  1. An international calling code (1 to 3 digits)
  2. An area code (usually 3 digits, but ranges from 1 to 5 digits)
  3. A phone number (usually 6 to 8 digits, but ranges from 4 to 13 digits)

So you have between 6 and 21 digits, with special thanks to Austria. =)

That being said, you can never be sure a phone number is valid unless you call the number. You will have people working their way around the validation (eg. by entering a valid, public number that doesn't belong to them), so you should ask yourself: "is this really necessary?"

往事风中埋 2024-07-22 07:39:01

有人打算将 libphonenumber 移植到 Perl,但还没有发生。

JavaScript 已经有了完整的移植。

到目前为止,Ruby、PHP 和 Python 的移植还不完整。 C++ 移植预计将在几个月内完成。

请密切关注:http://code.google.com/p/libphonenumber/任何其他已宣布的内容。

Someone was going to port libphonenumber to Perl, but it hasn't yet happened.

There is already a complete port to JavaScript.

There are incomplete ports to Ruby, PHP and Python so far. A C++ port is expected within months.

Keep an eye on: http://code.google.com/p/libphonenumber/ for any others as they are announced.

时光清浅 2024-07-22 07:39:01

扩展查斯。 Domchi 的观点: 验证电话号码有两个原因:

  1. 帮助用户正确输入他/她的号码(通常当用户希望您获得他们的号码时)
  2. 防止用户在未输入有效号码的情况下继续操作(通常当用户不愿意给你时)

如果你的情况是情况#1,那么简单的验证就足够了,因为你不想阻止边缘情况的正确输入并让你的用户感到沮丧,你只是想帮助他们避免错误输入他们的号码。

如果您的情况是情况#2,则无论进行多少验证都不会阻止用户输入不属于他们的有效号码。 要真正做到这一点,您需要使用验证码进行自动回调,在这种情况下,您现在更多的是情况#1,因为他们需要提供正确的号码才能获取验证码。 但这将需要更多的工作。

最后,您实际上只需要覆盖案例#1,帮助用户输入正确的数字。 不要仅仅因为电话号码验证而让潜在用户失望。

To expand on Chas. and Domchi's points: There are two reasons to validate a phone number:

  1. To help the user to correctly enter his/her number (often when the user WANTS you to have their number)
  2. To prevent the user from proceeding without entering a valid number (often when the user would rather not give it to you)

If your case is case #1 simple validation is all you need since you don't want to prevent a fringe case correct entry and frustrate your user, you simply want to help them from incorrectly entering their number.

If your case is case #2, no amount of validation will prevent a user from entering a valid number that isn't theirs. To really do this you would need to do an automated call-back with a validation code, in which case you are now more in case #1 since they will need to provide a correct number to get the validation code. This will be MUCH more work though.

In the end, you really only need to cover case #1, help the user to enter a correct number. Don't frustrate away a potential user, just due to phone number validation.

终止放荡 2024-07-22 07:39:01

我不懂 Perl,但这似乎是使用 Regexp 的完美案例。

但无论如何,每个国家/地区都需要一个,显然这不能包括世界上任何国家/地区,但您可以找到

I don't know Perl but that's semme to be a perfect case to use Regexp.

But anyway you will need one for each country, and obviously this can't include any country in the world but you can find phone patterns here.

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