using System; using System.Text; using System.Text.RegularExpressions; using System.Data; using EasyFuncLib; namespace Zhaizj.Framework { /// /// 基本数据类型判断 /// public class Utils { /// /// 验证是否为正整数 /// /// /// public static bool IsInt(string Expression) { if (Expression != null) { return Regex.IsMatch(Expression, @"^[0-9]+$"); } return false; } /// /// 是否为浮点数字 /// /// /// public static bool IsDouble(string Expression) { if (Expression != null) { return Regex.IsMatch(Expression, @"^\-?[0-9]+(\.[0-9]*)?$"); } return false; } /// /// 是否为中文字符 /// /// /// public static bool IsCh(string str) { return Regex.IsMatch(str, "^[\u4e00-\u9fa5]+$"); } /// /// 是否为数字字母和_ /// /// /// public static bool IsNormal(string Expression) { if (Expression != null) { return Regex.IsMatch(Expression, @"^[0-9a-zA-Z_]+$"); } return false; } /// /// 是否为数字字母汉字和_ /// /// /// public static bool IsNormalCh(string Expression) { if (Expression != null) { return Regex.IsMatch(Expression, @"^[0-9a-zA-Z\u4e00-\u9fa5_]+$"); } return false; } /// /// 是否为电话号码(未强制判断) /// /// /// public static bool IsPhone(string Expression) { if (Expression == "") return true; if (Expression != null) { return Regex.IsMatch(Expression, @"^[0-9\-.]+$"); } return false; } /// /// 判断Email地址 /// /// /// public static bool IsEmail(string Expression) { if (Expression != null) { return Regex.IsMatch(Expression, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); } return false; } /// /// 判断手机号码 /// /// /// public static bool IsMoblie(string Expression) { string regu = "^[1][3,5,8][0-9]{9}$"; if (!Regex.Match(Expression, regu, RegexOptions.Compiled).Success) { return false; } else { return true; } } /// /// 产生随机字符串 /// /// 要产生随机字符串的长度 /// public static string RandomString(int length) { Random ran = new Random(); string str = String.Empty; Char code; int num; for (int i = 0; i < length; i++) { num = ran.Next(); if (num % 2 == 0) { code = (char)('0' + (char)(num % 10)); } else { code = (char)('A' + (char)(num % 10)); } str += code; } return str; } /// /// 给Table加上编号 /// /// /// /// public static DataTable AddNumberTable(DataTable dt,String name) { dt.Columns.Add(name); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i][name] = (i + 1).ToString(); } return dt; } /// /// 中文转换为简拼 /// /// /// public static string GetJp(string chinese) { return Chinese2PinYin.GetFirstPinYin(chinese); } } }