EMAIL的验证

表中有列是EMAIL,但中间有很多错误。求段SQL让来检测EMAIL,错误的清空。
[41 byte] By [wth1150-@疯癫行者$] at [2008-4-12]
# 1
检查输入的是否含有 '@', 是否含有'.com'或'.net'等等
要全部过滤正确基本不可能
# 2
[a-z][0-9]@[a-z][0-9].[a-z][0-9]
wth1150-@疯癫行者$ at 2007-10-22 > top of Msdn China Tech,MS-SQL Server,应用实例...
# 3
求段SQL让来检测EMAIL,错误的清空

判断错误的标准是什么?
# 4
[a-z]@[a-z][0-9].[a-z][0-9]

[0-9]@[a-z][0-9].[a-z][0-9]

这样对不?
还有有没有长度限制?

# 5
插入之前判断,sqlserver没正则式,只有通配符
jaway-无限渴望 at 2007-10-22 > top of Msdn China Tech,MS-SQL Server,应用实例...
# 6
[a-z][0-9]@[a-z][0-9].[a-z][0-9]??

不对吧

那aaa@aa11.sss22这也对?
# 7
aaa@aa11.sss22 算对
只要求检测出一般的错误就好了
wth1150-@疯癫行者$ at 2007-10-22 > top of Msdn China Tech,MS-SQL Server,应用实例...
# 8
那楼主你的方法就可以了
# 9
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
hellowork-一两清风 at 2007-10-22 > top of Msdn China Tech,MS-SQL Server,应用实例...
# 10
mark
quanyi-长生天 at 2007-10-22 > top of Msdn China Tech,MS-SQL Server,应用实例...
# 11
学习中,,,,,,