C#验证字符串是否是数字,是否包括中文,是否是邮箱格式,是否是电话格式
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}$"); :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 RegSend = new Regex("[0-9]{1}([0-9]+){5}");
private static Regex RegUrl = new Regex("^[a-zA-z]+://(
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#验证字符串是否是数字,是否包括中文,是否是邮箱格式,是否是电话格式的更多相关文章
- php验证字符串是否以逗号隔开包括中文字符串
if(preg_match('/^[\x{4e00}-\x{9fa5}\w]+(,[\x{4e00}-\x{9fa5}\w]+)*$/u','体育,娱乐')){ echo 'ok';}
- JavaScript验证字符串只能包含数字或者英文字符的代码实例
验证字符串只能包含数字或者英文字符的代码实例:本章节分享一段代码实例,它实现了验证字符串内容是否只包含英文字符或者数字.代码实例如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
- php 正则验证字符串是否为数字
PHP 正则验证字符串是否为数字 方法一: php中利用正则表达式验证字符串是否为数字一件非常容易的事情,最主要的是如何写好正则表达式以及掌握正则表达式的写法,在此利用正则表达式的方式来列举一下判断数 ...
- java正则表达式应用--验证字符串是否为数字(转载)
首先说一下java正则表达式的重点概念: 第一.相关类:Pattern.Matcher 第二.典型的调用顺序是 Pattern p = Pattern.compile("a*b") ...
- java判断字符串是否为数字,包括负数
/** * 判断是否为数字,包含负数情况 * @param str * @return */ private boolean isNumeric(String str){ Boolean flag = ...
- c#拆分字符串英文和数字(包括国外所以文字)
先创建一个类: /// <summary> /// 字符串分析 /// </summary> interface IStringAna { /// <summary> ...
- asp.net检查验证字符串是否为纯数字方法小结
原文 asp.net检查验证字符串是否为纯数字方法小结 在asp.net中验证字符串是不是为数字我们没有像php中那么多丰富的函数来直接使用,这里我整理了一些比较实例的验证字符串是否为纯数字方法代码 ...
- C#判断字符串是否为数字字符串
在进行C#编程时候,有的时候我们需要判断一个字符串是否是数字字符串,我们可以通过以下两种方法来实现.[方法一]:使用 try{} catch{} 语句. 我们可以在try语句块中试图将str ...
- 验证一个字符串是否由数字组成(Java)
public class StringDemo{ public static void main(String args[]){ String str ="12343264sd6223&qu ...
随机推荐
- 双缓冲绘图和窗口控件的绘制——ATL ActiveX 窗口控件生成向导绘制代码OnDraw的一个错误 .
双缓冲绘图和窗口控件的绘制 ---ATL ActiveX 窗口控件生成向导绘制代码OnDraw的一个错误 cheungmine 我们通常使用ATL COM组件,生成一个带窗口的ActiveX控件,然后 ...
- BZOJ 3314: [Usaco2013 Nov]Crowded Cows( 单调队列 )
从左到右扫一遍, 维护一个单调不递减队列. 然后再从右往左重复一遍然后就可以统计答案了. ------------------------------------------------------- ...
- 《Swift Programming Language 》——Swift中怎样使用继承(Inheritance)
一个类能够继承(inherit)还有一个类的方法(methods),属性(property)和其他特性.当一个类继承其他类时,继承类叫子类(subclass),被继承类叫超类(或父类,supercla ...
- 4Sum -- LeetCode
原题链接: http://oj.leetcode.com/problems/4sum/ 这道题要求跟3Sum差点儿相同,仅仅是需求扩展到四个的数字的和了.我们还是能够依照3Sum中的解法,仅仅是在外 ...
- asp.net2.0安全性(1)--用户角色篇(代码实现1)--转载来自车老师
创建用户: MembershipCreateStatus mc; Membership.CreateUser(txtUid.Text, txtPwd.Text, txtEmail.Text, txtQ ...
- clearcase常用命令
版本控制工具学习 http://www.itpxpj.com/course.do?method=getAllCourseInFront&classTypeId=21 1.[ClearCase] ...
- QString与char*的相互转换
原地址:http://blog.sina.com.cn/s/blog_5c70dfc80100r0nh.html 一.QString转char* QString str; int num=0; s ...
- axure母版(模板)区域介绍
axure的模板区域是非常重要的一个功能,网站的头部.尾部部分等很多页面同时用到的内容,都可以使用母版,因为在母版中只需要修改一次,就可以实现所有的页面更新,可以大大的加速原型的制作速度.需要重复理解 ...
- eclipse插件maven的使用,web打包成WAR,tomcat下直接运行
1.首先下载maven 其下载地址为:http://maven.apache.org/download.html 下载apache-maven-3.0.3-bin.zip 环境变量配置为 变量 ...
- Cloudera Hadoop 4 实战课程(Hadoop 2.0、集群界面化管理、电商在线查询+日志离线分析)
课程大纲及内容简介: 每节课约35分钟,共不下40讲 第一章(11讲) ·分布式和传统单机模式 ·Hadoop背景和工作原理 ·Mapreduce工作原理剖析 ·第二代MR--YARN原理剖析 ·Cl ...