验证 SQL Server 2000 中的电话号码

发布于 2024-09-29 17:06:21 字数 202 浏览 4 评论 0原文

有没有人有一种使用 sql (SQL Server 2000) 验证电话号码的好方法。

我需要从数据库中选择具有有效电话号码的所有用户,

谢谢 Sp

Valid number 
08450000000
01332000000
07444000000
+441332000000

英国标准号码

Does anyone have a nifty way of validating telephone numbers using sql (SQL Server 2000).

I need to select all users fro ma Db that have valid phone number

Thanks
Sp

Valid number 
08450000000
01332000000
07444000000
+441332000000

Standard UK numbers

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

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

发布评论

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

评论(4

轻许诺言 2024-10-06 17:06:21

允许用户输入具有各种拨号前缀和标点符号的各种格式的号码。

去掉拨号前缀数字,删除空格和标点符号。验证号码的位数是否正确且在有效范围内,然后以 E.164 格式和完整的国家/地区代码将该号码存储在数据库中。

这使您可以在发生时进行批量区号更改,并可以轻松地明确提取某个国家/地区的所有号码。

存储数字时不要使用空格或标点符号。

使用特定于国家/地区的格式规则正确设置数字格式以供显示。

英国的数字相当复杂。这里有完整的数据:
http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers

它详细描述了选择、验证和格式化过程。

Allow the user to enter numbers in a variety of formats with various dial prefixes and punctuation.

Strip the dial prefix digits, remove spacing and punctuation. Validate the number has the right number of digits and is in a valid range and then store the number in your database in E.164 format with full country code.

This allows you to make bulk area code changes as they happen as well as make it easy to pull all numbers for a country unambiguously.

Store the number without spaces or punctuation.

Use country-specific formatting rules to format the number correctly for display.

UK numbers are quite complex. There's full data here:
http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers

It describes the selection, validation and formatting processes in detail.

风追烟花雨 2024-10-06 17:06:21

该网站对英国电话号码进行了极其彻底的验证,并提供 JavaScript、VBScript 和 JavaScript 代码示例。 PHP。您需要将其转换为在 SQL Server 存储过程中使用,但原则应该很容易遵循。

英国电话号码验证 - JavaScript、VBScript 和PHP

This website has extremely thorough validation for UK telephone numbers, with code examples in JavaScript, VBScript, & PHP. You will need to translate this to use in a SQL Server stored procedure, but the principle should be straightforward to follow.

UK Telephone Number Validation - JavaScript, VBScript, & PHP

贪恋 2024-10-06 17:06:21

如果您有一个正则表达式来匹配该数字,则可以在 SQL Server 上安装正则表达式扩展存储过程。我在工作中安装了这个扩展存储过程,并且我们经常使用它。有几个过程(每个过程都有相应的函数包装器):

  1. 检查匹配(是,否)
  2. 检查匹配(计数)
  3. 搜索和替换
  4. 格式
  5. 拆分

要查找匹配,您可以这样使用它:

 select number 
 from numberTable
 where dbo.fn_pcre_match(number, 'someRegex') = 1

其中“someRegex”是正则表达式匹配您正在寻找的格式。 此网站有一些匹配项,但我没有确定它们的效果如何,因为我不熟悉英国的数字。

If you have a regular expression to match the number, you can install a regex extended stored procedure on your SQL Server. I installed this extended stored procedure at work and we use it quite a bit. There are several procedures (each with corresponding function wrappers):

  1. check for matches (yes, no)
  2. check for matches (count)
  3. search and replace
  4. format
  5. split

To find matches you would use it as such:

 select number 
 from numberTable
 where dbo.fn_pcre_match(number, 'someRegex') = 1

Where 'someRegex' is the regular expression matching the format you are looking for. This site has some matches on it, but I'm not sure how well they work since I'm not familiar with UK numbers whatsoever.

旧情别恋 2024-10-06 17:06:21

我不知道定义有效英国电话号码的确切规则,并且由于您没有提供任何验证电话号码的规则,我只是选择了 Colin Pickard 在他的答案中提供的网址中列出的规则。

检查以下规则以验证英国电话号码 -
1. 提供的电话号码不为空
2. 电话号码不包含所需的 10 或 11 位数字。
3. 有效的完整英国电话号码必须以 0 开头。

如果我遗漏了任何规则,您也可以在此功能中添加对这些条件的检查。

ALTER FUNCTION [dbo].[ValidatePhoneNo] 
(   
    @PhoneNo varchar(20) 
)
RETURNS varchar(10)
AS
BEGIN
    DECLARE @Result varchar(10)
    SET @RESULT = 'invalid'

    IF len(@PhoneNo) > 9 AND len(@PhoneNo) < 12 AND @PhoneNo IS NOT NULL AND (substring(@PhoneNo,1,1) = 0)
    BEGIN
        SET @Result = 'valid'
    END

    RETURN @RESULT
END

I don't knwo the exact rules that define a valid UK phone number and as you have not provided any rules to validate a Phone no, I just picked rules listed in the url provided by Colin Pickard in his answer.

The following rules are checked for validating UK phone number -
1. Telephone number provided is not null
2. Telephone number does not contain the required 10 or 11 digits.
3. A valid full UK telephone numbers must start with a 0

If there are any rules that I missed out, you can add the check for those conditions too in this function.

ALTER FUNCTION [dbo].[ValidatePhoneNo] 
(   
    @PhoneNo varchar(20) 
)
RETURNS varchar(10)
AS
BEGIN
    DECLARE @Result varchar(10)
    SET @RESULT = 'invalid'

    IF len(@PhoneNo) > 9 AND len(@PhoneNo) < 12 AND @PhoneNo IS NOT NULL AND (substring(@PhoneNo,1,1) = 0)
    BEGIN
        SET @Result = 'valid'
    END

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