Dzwebs.Net

撰写电脑技术杂文十余年

asp.net后台代码判断字符串是否为电子邮件格式的代码

Admin | 2009-3-17 22:06:05 | 被阅次数 | 8192

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  首先在CS文件顶部引入:

  using System.Text.RegularExpressions;

  以下为代码说明

  一、验证函数

  private static bool IsEmail(string Str)
    {
        string strRegex = @"^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}$";
        Regex re = new Regex(strRegex);
        if (re.IsMatch(Str))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

  二、调用方法

  if (IsEmail(“abcdef@126.com“))
  {
    ResponseWrite(“邮件格式正确“);
  }

  经过验证,正确无误!

  以上代码运行环境为asp.net(c#)(最好是VS2005)


该杂文来自: 网站开发杂文

上一篇:修改上传图片的尺寸大小之NET2.0代码

下一篇:如何实现按回车键就执行多个按钮中的一个按钮事件

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计