1、删除字符串中不可见字符
public static string DeleteUnVisibleChar(string sourceString)
{
var sBuilder = new StringBuilder(131);
for (int i = 0; i < sourceString.Length; i++)
{
int Unicode = sourceString[i];
if (Unicode >= 16)
{
sBuilder.Append(sourceString[i].ToString());
}
}
return sBuilder.ToString();
}
2、是否数字判断
public static bool IsNumeric(string strInput)
{
if (string.IsNullOrEmpty(strInput))
return false;
var reg = new Regex(@"^[-]?\d+[.]?\d*$");
return reg.IsMatch(strInput);
}
3、是否时间类型判断
public static bool IsDateTime(string strDate)
{
var reg =
new Regex(
@"(((^((1[8-9]\d{2})|([2-9]\d{3}))([-\/\._])(10|12|0?[13578])([-\/\._])(3[01]|[12][0-9]|0?[1-9]))|(^((1[8-9]\d{2})|([2-9]\d{3}))([-\/\._])(11|0?[469])([-\/\._])(30|[12][0-9]|0?[1-9]))|(^((1[8-9]\d{2})|([2-9]\d{3}))([-\/\._])(0?2)([-\/\._])(2[0-8]|1[0-9]|0?[1-9]))|(^([2468][048]00)([-\/\._])(0?2)([-\/\._])(29))|(^([3579][26]00)([-\/\._])(0?2)([-\/\._])(29))|(^([1][89][0][48])([-\/\._])(0?2)([-\/\._])(29))|(^([2-9][0-9][0][48])([-\/\._])(0?2)([-\/\._])(29))|(^([1][89][2468][048])([-\/\._])(0?2)([-\/\._])(29))|(^([2-9][0-9][2468][048])([-\/\._])(0?2)([-\/\._])(29))|(^([1][89][13579][26])([-\/\._])(0?2)([-\/\._])(29))|(^([2-9][0-9][13579][26])([-\/\._])(0?2)([-\/\._])(29)))((\s+(0?[1-9]|1[012])(:[0-5]\d){0,2}(\s[AP]M))?$|(\s+([01]\d|2[0-3])(:[0-5]\d){0,2})?$))");
return reg.IsMatch(strDate);
}
4、是否邮件类型
public static bool IsEmail(string email)
{
email = email.Trim();
const string regexString =
@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
var regex = new Regex(regexString);
return regex.IsMatch(email);
}
5、本月多少天数判断
public static int GetDaysOfMonth(int iYear, int Month)
{
var days = 0;
switch (Month)
{
case 1:
days = 31;
break;
case 2:
days = IsRuYear(iYear) ? 29 : 28;
break;
case 3:
days = 31;
break;
case 4:
days = 30;
break;
case 5:
days = 31;
break;
case 6:
days = 30;
break;
case 7:
days = 31;
break;
case 8:
days = 31;
break;
case 9:
days = 30;
break;
case 10:
days = 31;
break;
case 11:
days = 30;
break;
case 12:
days = 31;
break;
}
return days;
}
6、返回当前日期是星期几
public static string GetWeekNameOfDay(DateTime dt)
{
string week = string.Empty;
switch (dt.DayOfWeek)
{
case DayOfWeek.Monday:
week = "星期一";
break;
case DayOfWeek.Tuesday:
week = "星期二";
break;
case DayOfWeek.Wednesday:
week = "星期三";
break;
case DayOfWeek.Thursday:
week = "星期四";
break;
case DayOfWeek.Friday:
week = "星期五";
break;
case DayOfWeek.Saturday:
week = "星期六";
break;
case DayOfWeek.Sunday:
week = "星期日";
break;
}
return week;
}