ms sql server中检测邮件地址的函数
2006-09-05 21:41
330 查看
if object_id('fnCheckEmail') is not null
drop function fnCheckEmail
GO
----创建验证函数,返回值为1表示正确,否则格式错误
create function fnCheckEmail(@Email varchar(1000))
returns bit
as
begin
declare @rtv bit
if
charindex(' ',@email) > 0 or /*含有空格*/
len(@email) - len(replace(@email,'.','')) > 1 or /*'.'超过1个*/
len(@email) - len(replace(@email,'@','')) > 1 or /*'@'超过1个*/
right(@email,1) = '.' or /*以'.'结尾*/
right(@email,1) = '@' or /*以'@'结尾*/
left(@email,1) = '.' or /*以'.'开头*/
left(@email,1) = '@' or /*以'.'开头*/
charindex('.',@email)-charindex('@',@email) < 0 or /*'.'在'@'前面*/
charindex('@',@email)-charindex('.',@email) = 1 or /*'@'与'.'相邻*/
charindex('.',@email)-charindex('@',@email) = 1 /*'@'与'.'相邻*/
set @rtv = 0
else
set @rtv = 1
return @rtv
end
GO
----创建测试数据
declare @t table(email varchar(1000))
insert @t
select 'ab.cxyz@s.com' union all
select 'ab@xyz@s.com' union all
select '@abc@xyz.com' union all
select 'abcxyz.com@' union all
select '.abcxyz@com' union all
select 'abc@xyz@com.' union all
select 'ab.c@xyzcom' union all
select 'abc@.com' union all
select 'abc@xyz.com' union all /*格式正确*/
select 'ab c@xyzcom'
----验证
select *,case dbo.fnCheckEmail(email) when 1 then '正确' else '错误' end from @t
----清除测试环境
drop function fnCheckEmail
drop function fnCheckEmail
GO
----创建验证函数,返回值为1表示正确,否则格式错误
create function fnCheckEmail(@Email varchar(1000))
returns bit
as
begin
declare @rtv bit
if
charindex(' ',@email) > 0 or /*含有空格*/
len(@email) - len(replace(@email,'.','')) > 1 or /*'.'超过1个*/
len(@email) - len(replace(@email,'@','')) > 1 or /*'@'超过1个*/
right(@email,1) = '.' or /*以'.'结尾*/
right(@email,1) = '@' or /*以'@'结尾*/
left(@email,1) = '.' or /*以'.'开头*/
left(@email,1) = '@' or /*以'.'开头*/
charindex('.',@email)-charindex('@',@email) < 0 or /*'.'在'@'前面*/
charindex('@',@email)-charindex('.',@email) = 1 or /*'@'与'.'相邻*/
charindex('.',@email)-charindex('@',@email) = 1 /*'@'与'.'相邻*/
set @rtv = 0
else
set @rtv = 1
return @rtv
end
GO
----创建测试数据
declare @t table(email varchar(1000))
insert @t
select 'ab.cxyz@s.com' union all
select 'ab@xyz@s.com' union all
select '@abc@xyz.com' union all
select 'abcxyz.com@' union all
select '.abcxyz@com' union all
select 'abc@xyz@com.' union all
select 'ab.c@xyzcom' union all
select 'abc@.com' union all
select 'abc@xyz.com' union all /*格式正确*/
select 'ab c@xyzcom'
----验证
select *,case dbo.fnCheckEmail(email) when 1 then '正确' else '错误' end from @t
----清除测试环境
drop function fnCheckEmail
相关文章推荐
- python写的调用ms sqlserver数据并发送邮件的小程序
- MS Sql Server中update()函数的作用?
- 几个在MS SQL Server处理IP的函数/存储过程
- MS SQL Server常用管理sql statement--发送邮件
- 用SQL语句查找包含有某个关键字的存储过程、触发器、函数等(仅适用MS SQL SERVER)
- 用Installshield 12 检测是否安装MS SQL Server或MSDE
- MS SQL Server结果生成HTML表格并发送邮件
- MS SQL Server中数据表、视图、函数/方法、存储过程是否存在判断及创建
- ms sqlserver 常用T-sql语句与函数
- MS SQL Server 2008 简体中文正式版下载地址(附序列号)
- MS SQL Server 2008 简体中文正式版下载地址(附序列号)
- MySQL ,MS SQL Server,类似功能的函数
- MS sql server中时间函数用法详解 DATEADD DATEDIFF
- MS SQL Server 2008 简体中文正式版下载地址(附序列号)
- MS SQL Server和Oracle的常用函数对比
- Oracle和MS SQL server的函数对比
- sqlserver有没有类似sys_connect_by_path的函数-MS-SQLServer/基础类
- MS SQL Server 2005 免费下载地址
- MS SQL Server时间常用函数
- MS SQL Server字符拆分函数