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. xmlns:android="http://schemas.android.com/apk/res/android的作用是

    xmlns:android="http://schemas.android.com/apk/res/android的作用是 这个是xml的命名空间,有了他,你就可以alt+/作为提示,提示你 ...

  2. Jquery学习笔记:事件处理基础介绍

    一.引子 给html的元素添加一个响应事件,最简单的办法是直接在元素标签内填写事件属性,先看一个最简单的例子 <!DOCTYPE html> <html lang="zh- ...

  3. POJ 2455 网络流 基础题 二分+网络流 dicnic 以及 sap算法

    Secret Milking Machine Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8189   Accepted: ...

  4. 给你的Cordova HybridApp加入Splash启动页面

    如今最新的Cordova 3以上的版本号支持启动画面了,是通过cordova插件实现的. 眼下Splash插件支持android,ios,blackberry等多个平台. 加入插件等步骤例如以下: 加 ...

  5. 【Unity 3D】使用 2DToolkit 插件 制作2D精灵动画

    话说博客传图也太麻烦了吧,一个一个文件一个一个传....为什么不能直接粘贴了,自动上传呢... 刚直接粘贴了,结果一张图没有,又重新截一次图,在传了一次...真是太**了 好了,吐槽完了,开始博客吧 ...

  6. AVL树的插入删除查找算法实现和分析-1

    至于什么是AVL树和AVL树的一些概念问题在这里就不多说了,下面是我写的代码,里面的注释非常详细地说明了实现的思想和方法. 因为在操作时真正需要的是子树高度的差,所以这里采用-1,0,1来表示左子树和 ...

  7. 初入Android--Activate生命周期

    Activate的主要生命周期 (注意:这只是主要的生命周期,而不是完整的生命周期方法,其中的两个周期之间可能还执行了其他的一些方法) 每个时刻在屏幕上的状态 进入onCreate方法:Activat ...

  8. 硬盘被误格式化或Ghost还原后的数据恢复

    硬盘格式化(Ghost还原)后的数据恢复 ---diskgenius使用之数据恢复 问题引出:计算机中病毒后用Ghost版本的winxp安装,由于安装途中选择了把映像安装到硬盘而不是分区,安装好后只剩 ...

  9. codility上的问题(18) Rho 2012

    从正整数1开始,产生一个数列,数列中的每个数是之前出现过的任意两个数的和(可以相等),问产生正整数A,需要的数列长度至少是多少?返回这样一个最短的序列. 例如A=42 可以这样[1, 2, 3, 6, ...

  10. python学习——截图工具编写

    学习一门语言最好的方法便是实践,想要拿Python写一个截图工具,网上一搜资料果然已经很多,前辈们都已经做的很到位了.现在就一步步来学习一下: 首先学习截图整个桌面的方法,可以使用Python中的PI ...