没有合适的资源?快使用搜索试试~ 我知道了~
字符串正则
资源推荐
资源详情
资源评论
//判断部分
public class GF_IsOk
{
/// <summary>
/// 判读是否是IP地址
/// </summary>
/// <param name="in_str"></param>
/// <returns></returns>
public static bool IsIPStr(string in_str)
{
IPAddress ip;
return IPAddress.TryParse(in_str, out ip);
}
/// <summary>
/// 判断是否是数字
/// </summary>
/// <param name="strNumber"></param>
/// <returns></returns>
public static bool IsNumber(string strNumber)
{
Regex objNotNumberPattern = new Regex("[^0-9.-]");
Regex objTwoDotPattern = new Regex("[0-9]*[.][0-9]*[.][0-9]*");
Regex objTwoMinusPattern = new Regex("[0-9]*[-][0-9]*[-][0-9]*");
String strValidRealPattern = "^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$";
String strValidIntegerPattern = "^([-]|[0-9])[0-9]*$";
Regex objNumberPattern = new Regex("(" + strValidRealPattern + ")|(" + strValidIntegerPattern + ")");
return !objNotNumberPattern.IsMatch(strNumber) &&
!objTwoDotPattern.IsMatch(strNumber) &&
public class GF_IsOk
{
/// <summary>
/// 判读是否是IP地址
/// </summary>
/// <param name="in_str"></param>
/// <returns></returns>
public static bool IsIPStr(string in_str)
{
IPAddress ip;
return IPAddress.TryParse(in_str, out ip);
}
/// <summary>
/// 判断是否是数字
/// </summary>
/// <param name="strNumber"></param>
/// <returns></returns>
public static bool IsNumber(string strNumber)
{
Regex objNotNumberPattern = new Regex("[^0-9.-]");
Regex objTwoDotPattern = new Regex("[0-9]*[.][0-9]*[.][0-9]*");
Regex objTwoMinusPattern = new Regex("[0-9]*[-][0-9]*[-][0-9]*");
String strValidRealPattern = "^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$";
String strValidIntegerPattern = "^([-]|[0-9])[0-9]*$";
Regex objNumberPattern = new Regex("(" + strValidRealPattern + ")|(" + strValidIntegerPattern + ")");
return !objNotNumberPattern.IsMatch(strNumber) &&
!objTwoDotPattern.IsMatch(strNumber) &&
!objTwoMinusPattern.IsMatch(strNumber) &&
objNumberPattern.IsMatch(strNumber);
}
/// <summary>
/// 判断是否是日期字符串
/// </summary>
/// <param name="in_str"></param>
/// <returns></returns>
public static bool IsDateStr_yyyymmdd(string in_str)
{
if (in_str == "") return true;
if (in_str.Length != 8) return false;
return IsDateStr(in_str);
}
/// <summary>
/// 判断是否是日期字符串
/// </summary>
/// <param name="in_str"></param>
/// <returns></returns>
public static bool IsDateStr(string in_str)
{
if (in_str == "") return true;
if (in_str.Length == 8)
in_str = in_str.Substring(0, 4) + "-" + in_str.Substring(4, 2) + "-" + in_str.Substring(6, 2);
DateTime dtDate;
bool bValid = true;
try
{
objNumberPattern.IsMatch(strNumber);
}
/// <summary>
/// 判断是否是日期字符串
/// </summary>
/// <param name="in_str"></param>
/// <returns></returns>
public static bool IsDateStr_yyyymmdd(string in_str)
{
if (in_str == "") return true;
if (in_str.Length != 8) return false;
return IsDateStr(in_str);
}
/// <summary>
/// 判断是否是日期字符串
/// </summary>
/// <param name="in_str"></param>
/// <returns></returns>
public static bool IsDateStr(string in_str)
{
if (in_str == "") return true;
if (in_str.Length == 8)
in_str = in_str.Substring(0, 4) + "-" + in_str.Substring(4, 2) + "-" + in_str.Substring(6, 2);
DateTime dtDate;
bool bValid = true;
try
{
剩余5页未读,继续阅读
资源评论
不想飞的天鹅
- 粉丝: 2
- 资源: 47
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功