經測試可用的正則表達式
private bool IsMath(string StrData)
{
//1.IsNum
//輸入的字符全是0~9
//Regex res = new Regex(@"^[0-9]*$");
//2.IsChar
//輸入的字符全是大小寫字母
// Regex res = new Regex(@"^[A-Za-z]+$");
//3.IsChinese
//輸入字符全是中文
// Regex res = new Regex(@"^[\u4e00-\u9fa5]{0,}$");
//4.IsEmail
//輸入電子郵件
// Regex res = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
//5.IsInteger
//輸入零或者非零數字
//Regex res = new Regex(@"^(0|[1-9][0-9]*)$");
//6.IsNumChar
//輸入數字或者字母
// Regex res = new Regex(@"^[A-Za-z0-9]+$");
//7.IsNum_Char
//輸入字符,數字,下劃線
//Regex res = new Regex(@"^\w+$");
//8.IsUrl
//輸入互聯網網址
// Regex res = new Regex(@"^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$");
//9.IsMonth
//輸入月份
// Regex res = new Regex(@"^(0?[1-9]|1[0-2])$");
//10.IsDate
//輸入天數
//Regex res = new Regex("^((0?[1-9])|((1|2)[0-9])|30|31)$");
////////11.IsTel
//不能用
//////Regex res = new Regex(@"^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$");
//12.IsDouble
//輸入且只能輸入兩位小數
// Regex res = new Regex(@"^[0-9]+(.[0-9]{2})?$");
//13.IsIp
//輸入IP
//Regex res = new Regex(@"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
//14.IsQQ
//驗證QQ號碼,號碼從1000開始
// Regex res = new Regex(@"[1-9][0-9]{4,}");
//15.IsPostCode
//驗證是否郵政編碼
// Regex res = new Regex(@"[1-9]\d{5}(?!\d)");
//16.IsIDNO
//驗證身份證號碼,後面不能爲X/Y
//Regex res = new Regex(@"\d{15}|\d{18}");
//17.IsPInteger
// Regex res = new Regex(@"^[1-9]\d*$");
//18.IsNInteger
//驗證負整數
//Regex res = new Regex(@"^-[1-9]\d*$");
//19.IsFloat
//驗證浮點數
//必須要有小數點
//Regex res = new Regex(@"^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$");
//20.IsPFloat
//必須要有小數點
Regex res = new Regex(@"^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$");
return res.IsMatch(StrData);
}
}
}
/*
匹配特定數字:
^[1-9]\d*$ //匹配正整數
^-[1-9]\d*$ //匹配負整數
^-?[1-9]\d*$ //匹配整數
^[1-9]\d*|0$ //匹配非負整數(正整數 + 0)
^-[1-9]\d*|0$ //匹配非正整數(負整數 + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ //匹配正浮點數
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ //匹配負浮點數
^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$ //匹配浮點數
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ //匹配非負浮點數(正浮點數 + 0)
^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ //匹配非正浮點數(負浮點數 + 0)
評註:處理大量數據時有用,具體應用時注意修正
匹配特定字符串:
^[A-Za-z]+$ //匹配由26個英文字母組成的字符串
^[A-Z]+$ //匹配由26個英文字母的大寫組成的字符串
^[a-z]+$ //匹配由26個英文字母的小寫組成的字符串
^[A-Za-z0-9]+$ //匹配由數字和26個英文字母組成的字符串
^\w+$ //匹配由數字、26個英文字母或者下劃線組成的字符串
*/
{
//1.IsNum
//輸入的字符全是0~9
//Regex res = new Regex(@"^[0-9]*$");
//2.IsChar
//輸入的字符全是大小寫字母
// Regex res = new Regex(@"^[A-Za-z]+$");
//3.IsChinese
//輸入字符全是中文
// Regex res = new Regex(@"^[\u4e00-\u9fa5]{0,}$");
//4.IsEmail
//輸入電子郵件
// Regex res = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
//5.IsInteger
//輸入零或者非零數字
//Regex res = new Regex(@"^(0|[1-9][0-9]*)$");
//6.IsNumChar
//輸入數字或者字母
// Regex res = new Regex(@"^[A-Za-z0-9]+$");
//7.IsNum_Char
//輸入字符,數字,下劃線
//Regex res = new Regex(@"^\w+$");
//8.IsUrl
//輸入互聯網網址
// Regex res = new Regex(@"^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$");
//9.IsMonth
//輸入月份
// Regex res = new Regex(@"^(0?[1-9]|1[0-2])$");
//10.IsDate
//輸入天數
//Regex res = new Regex("^((0?[1-9])|((1|2)[0-9])|30|31)$");
////////11.IsTel
//不能用
//////Regex res = new Regex(@"^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$");
//12.IsDouble
//輸入且只能輸入兩位小數
// Regex res = new Regex(@"^[0-9]+(.[0-9]{2})?$");
//13.IsIp
//輸入IP
//Regex res = new Regex(@"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
//14.IsQQ
//驗證QQ號碼,號碼從1000開始
// Regex res = new Regex(@"[1-9][0-9]{4,}");
//15.IsPostCode
//驗證是否郵政編碼
// Regex res = new Regex(@"[1-9]\d{5}(?!\d)");
//16.IsIDNO
//驗證身份證號碼,後面不能爲X/Y
//Regex res = new Regex(@"\d{15}|\d{18}");
//17.IsPInteger
// Regex res = new Regex(@"^[1-9]\d*$");
//18.IsNInteger
//驗證負整數
//Regex res = new Regex(@"^-[1-9]\d*$");
//19.IsFloat
//驗證浮點數
//必須要有小數點
//Regex res = new Regex(@"^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$");
//20.IsPFloat
//必須要有小數點
Regex res = new Regex(@"^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$");
return res.IsMatch(StrData);
}
}
}
/*
匹配特定數字:
^[1-9]\d*$ //匹配正整數
^-[1-9]\d*$ //匹配負整數
^-?[1-9]\d*$ //匹配整數
^[1-9]\d*|0$ //匹配非負整數(正整數 + 0)
^-[1-9]\d*|0$ //匹配非正整數(負整數 + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ //匹配正浮點數
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ //匹配負浮點數
^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$ //匹配浮點數
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ //匹配非負浮點數(正浮點數 + 0)
^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ //匹配非正浮點數(負浮點數 + 0)
評註:處理大量數據時有用,具體應用時注意修正
匹配特定字符串:
^[A-Za-z]+$ //匹配由26個英文字母組成的字符串
^[A-Z]+$ //匹配由26個英文字母的大寫組成的字符串
^[a-z]+$ //匹配由26個英文字母的小寫組成的字符串
^[A-Za-z0-9]+$ //匹配由數字和26個英文字母組成的字符串
^\w+$ //匹配由數字、26個英文字母或者下劃線組成的字符串
*/
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.