求用RegularExpressionValidator验证电子邮件的正则表达式的代码

解决方案 »

  1.   

    用函数也可以啊
    Public Function IsEmail(ByVal email as string) as boolean
    dim names() as string
    dim name as string
    dim i as integer
    dim c as string

    names = split(email,"@")

    if Ubound(names) <> 1 then
       return false
    end if
    for each name in names
       if Len(name) <= 0 then
         return false
       end if
       for i = 1 to Len(name)
         c = Lcase(Mid(name, i, 1))
         if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
           return false
         end if
       next
       if Left(name, 1) = "." or Right(name, 1) = "." then
          return false
       end if
    next
    if InStr(names(1), ".") <= 0 then
       return false
    end if
    i = Len(names(1)) - InStrRev(names(1), ".")
    if i <> 2 and i <> 3 then
       return false
    end if
    if InStr(email, "..") > 0 then
       return false
    end if

    return true

    end function
      

  2.   

    http://chs.gotdotnet.com/quickstart/howto/doc/regexcommon.aspx
      

  3.   

    在aspx页面上加一个RegularExpressionValidator
    在属性里找到RegularExpression,单击...,里面就有email的正则表达式
      

  4.   

    各种免费/收费邮箱对于用户名的要求都有些小区别下面以网易(163.com)的免费邮箱为例她的要求是:用户名由a~z的英文字母(不区分大小写)、0~9的数字、点、减号或下划线组成,长度为3~18个字符,例如:kyzy_001。正则表达式是:[\w\.-]{3,18}@([\w-]+\.)+[\w-]+
      

  5.   

    "^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$"   //Email
      

  6.   

    to:bzscs(沙虫 我爱小美) 
    你对比一下你的函数和别人提供的正则表达式,看看哪个更简洁?^([0-9a-zA-Z]+[-._+&amp;])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$