求一个SQL SERVER 2005 正则匹配手机号的函数写法
求一个SQL SERVER 2005 正则匹配手机号的函数写法
CREATE function dbo.regexReplace
@str char(11)
as
declare @result int
begin
//这里应该怎么样实现将传进来的参数去验证是否合法的手机号呢?
return @result
end
SQL?Server?2005 正则 函数
[解决办法]
create function dbo.regexReplace(@str char(11))
RETURNS int
as
begin
DECLARE @result INT
SET @result = 0
IF (LEFT(@str, 3) IN ('130','131','132','133','134','135','136','137','138','139','150','153','156','157','158','159','188','189')
AND PATINDEX('[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]', @str) = 1)
begin
SET @result = 1
end
RETURN @result
end
--楼主测试下:
SELECT dbo.regexReplace('')
SELECT dbo.regexReplace('13312345678')
SELECT dbo.regexReplace('1331234567')
SELECT dbo.regexReplace('13312.45678')