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. 微信或手机浏览器在线显示office文件(已測试ios、android)

    近期开发微信企业号,发现微信andriod版内置浏览器在打开文件方面有问题,可是ios版没有问题.原因是ios版使用的是safari浏览器 支持文档直接打开.可是andriod版使用的是腾讯浏览器x5 ...

  2. CIconListBox带图标的列表框类

    有时候,我们需要在列表框ListBox中插入带图标的文字项,这就需要自己派生一个类出来了,网上的一个CIconListBox类还不错,网站http://www.codeguru.com/Cpp/con ...

  3. hive regex insert join group cli

    1.insert Insert时,from子句既能够放在select子句后,也能够放在insert子句前,以下两句是等价的 hive> FROM invites a INSERT OVERWRI ...

  4. Maven项目红色叹号+JavaWeb: 报错信息The superclass &quot;javax.servlet.http.HttpServlet&quot; was not found on the Java B

    昨天写的关于解决JavaWeb: 报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the ...

  5. 华为手机logcat不出日志解决方案

    解决方法:在拨打电话界面,录入*#*#2846579#*#* 自动进入开发界面菜单,进入第一个,选择开启logcat.

  6. linux内核中send与recv函数详解

    Linux send与recv函数详解 1.简介 #include <sys/socket.h> ssize_t recv(int sockfd, void *buff, size_t n ...

  7. (摘录)ASP.NET提供文件下载函数(支持大文件、续传、速度限制、资源占用小)

    // 输出硬盘文件,提供下载 // 输入参数 _Request: Page.Request对象, _Response: Page.Response对象, _fileName: 下载文件名, _full ...

  8. Spring3表达式语言(SpEL)学习笔记

    最新地址请访问:http://leeyee.github.io/blog/2011/06/19/spring-expression-language Spring Excpression Langua ...

  9. 杭电 1711 Number Sequence

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  10. Android ListView 单条刷新方法实践及原理解析

    对于使用listView配合adapter进行刷新的方法大家都不陌生,先刷新adapter里的数据,然后调用notifydatasetchange通知listView刷新界面. 方法虽然简单,但这里面 ...