首先要搞清email字段的有效性标准是什么。
什么样的email算作有效?

解决方案 »

  1.   

    lovvver(春晖) ( ):这个你不清楚么??
      

  2.   

    不要什么都交给SQL做,现在的客户机都是很好的,交给前台应用程序做就行了
      

  3.   

    我写了个函数,请各位给点意见。
    里面很乱,当执行到判断登陆名里是否存在非法字符时,会有点问题。
    另外,还有哪些没有考虑到的限制,望大家提出来。if exists(select * from sysobjects where name='check_email')
    drop function check_email
    go
    ----email的用户名部分是由数字,字母,小数点,下划线组成。
    create function check_email(@email varchar(255))
    returns char(1) as --0:非法;1:合法
    begin
    declare @sit1 int, --@的位置
            @sit2 int, --.的位置
            @tail varchar(20), --后缀名
            @flag1 char(1),  --后缀是否合法
            @flag2 char(1),--@和.的位置是否正确
            @flag3 char(1),--用户名是否以字母开头
            @sit3  int,    --如果有大于1个@,则第2个@的位置
            @flag4 char(1),--如果@的个数>1,则为0;否则为1
            @flag5 char(1),--登陆名是否合法
            @n    int,      --判断登陆名字母是否合法的循环次数
            @m    char(1),  --第@n个字母
            @return char(1) --返回值 0:非法;1:合法
    select @flag1='0',@flag2='0',@flag3='0',@flag4='0',@flag5='0'
    select @sit1=charindex('@',@email)
    select @sit2=charindex('.',right(@email,len(@email)-@sit1))
    select @tail=right(@email,len(@email)-@sit1-@sit2)
    select @n=1
    select @return='0'
    select @sit3=charindex('@',right(@email,len(@email)-@sit1))
    login: select @flag5='0'
    while @n<=@sit1-1
    begin
    select @m=substring(@email,@n,1)
     if ascii(@m) in(46,95) or ascii(@m) between 48 and 57 or ascii(@m) between 65 and 90 or ascii(@m) between 97 and 122
     select @flag5='1'
     else
     goto login
    select @n=@n+1
    end
    --判断标志
    if @tail in('com','com.cn','net','org','cn','net.cn','gov','gov.cn','org.cn','edu.cn','info','biz','tv','cc','name','中国','网络','公司')
      select @flag1='1'if @sit2<>0
      select @flag2='1'if ascii(left(@email,1)) between 65 and 90 or ascii(left(@email,1)) between 97 and 122
     select @flag3='1'if @sit3=0
     select @flag4 = '1'--是否合法
    if @flag1='1' and @flag2='1' and @flag3='1' and @flag4='1' and @flag5='1'
     select @return ='1'if @@error<>0
      select @return='0'return @return
    end--select dbo.check_email('[email protected]')