using System;

    using System.Web;

    using System.Text;

    using System.Web.UI.WebControls;

    using System.Text.RegularExpressions;

public class ValidateHelper

    {

        private static Regex RegNumber = new Regex("^[0-9]+$");

        private static Regex RegNumberSign = new Regex("^[+-]?[0-9]+$");

        private static Regex RegDecimal = new Regex("^[0-9]+[.]?

[0-9]+$");

        private static Regex RegDecimalSign = new Regex("^[+-]?[0-9]+[.]?[0-9]+$");

        private static Regex RegEmail = new Regex("^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info)$");

        private static Regex RegCHZN = new Regex("[\u4e00-\u9fa5]");

        private static Regex RegTell = new Regex("^(([0-9]{3,4}-)|[0-9]{3.4}-)?

[0-9]{7,8}$");

        private static Regex RegSend = new Regex("[0-9]{1}([0-9]+){5}");

        private static Regex RegUrl = new Regex("^[a-zA-z]+://(

:25[0-5]|2[0-4]\\d|[01]?\\d?

\\d))$">\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?|[a-zA-z]+://((?:(?:25[0-5]|2[0-4]\\d|[01]?

\\d?

\\d)\\.){3}(?

:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))$");

        private static Regex RegMobilePhone = new Regex("^13|15|18[0-9]{9}$");

        private static Regex RegMoney = new Regex("^[0-9]+|[0-9]+[.]?[0-9]+$");

#region 数字字符串检查

/// <summary>

        /// 是否数字字符串

        /// </summary>

        /// <param name="inputData">输入字符串</param>

        public static bool IsNumber(string inputData)

        {

            if (!string.IsNullOrEmpty(inputData))

            {

                Match m = RegNumber.Match(inputData);

                return m.Success;

            }

            else

            {

                return false;

            }

        }

/// <summary>

        /// 是否数字字符串 可带正负号

        /// </summary>

        /// <param name="inputData">输入字符串</param>

        public static bool IsNumberSign(string inputData)

        {

            Match m = RegNumberSign.Match(inputData);

            return m.Success;

        }

/// <summary>

        /// 是否是浮点数

        /// </summary>

        /// <param name="inputData">输入字符串</param>

        public static bool IsDecimal(string inputData)

        {

            Match m = RegDecimal.Match(inputData);

            return m.Success;

        }

/// <summary>

        /// 是否是浮点数 可带正负号

        /// </summary>

        /// <param name="inputData">输入字符串</param>

        public static bool IsDecimalSign(string inputData)

        {

            Match m = RegDecimalSign.Match(inputData);

            return m.Success;

        }

#endregion

#region 中文检測

/// <summary>

        /// 检測是否有中文字符

        /// </summary>

        public static bool IsHasCHZN(string inputData)

        {

            Match m = RegCHZN.Match(inputData);

            return m.Success;

        }

#endregion

#region 邮件地址

        /// <summary>

        /// 是否是邮箱

        /// </summary>

        /// <param name="inputData">输入字符串</param>

        public static bool IsEmail(string inputData)

        {

            Match m = RegEmail.Match(inputData);

            return m.Success;

        }

#endregion

#region 电话,邮政编码,网络地址,手机号码,价格

        /// <summary>

        /// 验证是否是电话

        /// </summary>

        public static bool IsPhone(string inputDate)

        {

            if (!string.IsNullOrEmpty(inputDate))

            {

                Match m = RegTell.Match(inputDate);

                return m.Success;

            }

            else

            {

                return false;

            }

        }

        /// <summary>

        /// 是否是邮政编码

        /// </summary> 

        public static bool IsSend(string inputDate)

        {

            if (!string.IsNullOrEmpty(inputDate))

            {

                Match m = RegSend.Match(inputDate);

                return m.Success;

            }

            else

            {

                return false;

            }

        }

        /// <summary>

        /// 是否是网络地址

        /// </summary>

        public static bool IsUrl(string inputDate)

        {

            Match m = RegUrl.Match(inputDate);

            return m.Success;

        }

        /// <summary>

        /// 是否是手机号码

        /// </summary>

        public static bool IsMobilePhone(string inputDate)

        {

            Match m = RegMobilePhone.Match(inputDate);

            return m.Success;

        }

        /// <summary>

        /// 是否是价格

        /// </summary>

        public static bool IsMoney(string inputDate)

        {

            Match m = RegMoney.Match(inputDate);

            return m.Success;

        }

        #endregion

        #region 是否是时间格式

        /// <summary>

        /// 推断一个字符串是否时间格式

        /// </summary>

        /// <param name="inputData">输入字符串</param>

        /// <returns></returns>

        public static bool IsDateTime(string inputData)

        {

            try

            {

                Convert.ToDateTime(inputData);

                return true;

            }

            catch

            {

                return false;

            }

        }

#endregion

    }

C#验证字符串是否是数字,是否包括中文,是否是邮箱格式,是否是电话格式的更多相关文章

  1. php验证字符串是否以逗号隔开包括中文字符串

    if(preg_match('/^[\x{4e00}-\x{9fa5}\w]+(,[\x{4e00}-\x{9fa5}\w]+)*$/u','体育,娱乐')){ echo 'ok';}

  2. JavaScript验证字符串只能包含数字或者英文字符的代码实例

    验证字符串只能包含数字或者英文字符的代码实例:本章节分享一段代码实例,它实现了验证字符串内容是否只包含英文字符或者数字.代码实例如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  3. php 正则验证字符串是否为数字

    PHP 正则验证字符串是否为数字 方法一: php中利用正则表达式验证字符串是否为数字一件非常容易的事情,最主要的是如何写好正则表达式以及掌握正则表达式的写法,在此利用正则表达式的方式来列举一下判断数 ...

  4. java正则表达式应用--验证字符串是否为数字(转载)

    首先说一下java正则表达式的重点概念: 第一.相关类:Pattern.Matcher 第二.典型的调用顺序是 Pattern p = Pattern.compile("a*b") ...

  5. java判断字符串是否为数字,包括负数

    /** * 判断是否为数字,包含负数情况 * @param str * @return */ private boolean isNumeric(String str){ Boolean flag = ...

  6. c#拆分字符串英文和数字(包括国外所以文字)

    先创建一个类: /// <summary> /// 字符串分析 /// </summary> interface IStringAna { /// <summary> ...

  7. asp.net检查验证字符串是否为纯数字方法小结

    原文  asp.net检查验证字符串是否为纯数字方法小结 在asp.net中验证字符串是不是为数字我们没有像php中那么多丰富的函数来直接使用,这里我整理了一些比较实例的验证字符串是否为纯数字方法代码 ...

  8. C#判断字符串是否为数字字符串

    在进行C#编程时候,有的时候我们需要判断一个字符串是否是数字字符串,我们可以通过以下两种方法来实现.[方法一]:使用 try{} catch{} 语句.      我们可以在try语句块中试图将str ...

  9. 验证一个字符串是否由数字组成(Java)

    public class StringDemo{ public static void main(String args[]){ String str ="12343264sd6223&qu ...

随机推荐

  1. 在Windows下编译OpenSSL(VS2005和VC6)

    需要说明的是请一定安装openssl-0.9.8a .  openssl-1.0.0我没有编译成功. 如何在Windows下编译OpenSSL (Vs2005使用Vc8的cl编译器)1.安装Activ ...

  2. Vim的常用命令笔记

    [简介] Vim是vi编辑器的改进版.vi是类UNIX系统里最常用的编辑器. [模式] 在shell中直接打vim filename就会进入普通模式.按i键进入编辑模式,此时Vim底部显示INSERT ...

  3. 读取中兴3G告警log告警文件到集合

    1.文件格式 ALARM_ID=102305_404205 EVENT_TIME=-- :: NOTIFICATION_TYPE= MANAGED_OBJECT_INSTANCE=NodeId=,Bs ...

  4. uva 620 Cellular Structure

    题目连接:620 - Cellular Structure 题目大意:给出一个细胞群, 判断该细胞的可能是由哪一种生长方式的到的, 输出该生长方式的最后一种生长种类, "SIMPLE&quo ...

  5. nginx使用自认证的https证书

    生成证书 可以通过以下步骤生成一个简单的证书: 创建服务器私钥: $ openssl genrsa -out server.key 2048 需要输入一系列的信息 创建签名请求的证书(CSR): $ ...

  6. 网页调试技巧:抓取马上跳转的页面POST信息或者页面内容

    http://www.qs5.org/Post/625.html 网页调试技巧:抓取马上跳转的页面POST信息或者页面内容 2016/02/02 | 心得分享 | 0 Replies 有时候调试网页或 ...

  7. 基于redis的cas集群配置(转)

    1.cas ticket统一存储 做cas集群首先需要将ticket拿出来,做统一存储,以便每个节点访问到的数据一致.官方提供基于memcached的方案,由于项目需要,需要做计入redis,根据官方 ...

  8. 将网站部署到服务器上出现_STORAGE_WRITE_ERROR_问题

    用的thinkphp3.2的框架,在本地运行没有问题,部署到服务器上(基于centos的LAMP环境)即报错,报错信息如下(完全看不懂...):求大神帮帮忙~~~~(>_<)~~~~ :( ...

  9. cocos2d-x游戏开发(十五)游戏加载动画loading界面

    个人原创,欢迎转载:http://blog.csdn.net/dawn_moon/article/details/11478885 这个资源加载的loading界面demo是在玩客网做逆转三国的时候随 ...

  10. Codeforces 484B Maximum Value(排序+二分)

    题目链接: http://codeforces.com/problemset/problem/484/B 题意: 求a[i]%a[j] (a[i]>a[j])的余数的最大值 分析: 要求余数的最 ...