using System;
using Shared;
using System.Text.RegularExpressions;
namespace HDL_ON
{
///
/// 常用工具类
///
public class Utlis
{
///
/// 全局打印
///
public static void WriteLine(object mes)
{
#if DEBUG
Console.WriteLine(mes);
#endif
}
///
/// 弹窗提示
///
///
public static void ShowAlertOnMainThread(string mes)
{
Application.RunOnMainThread(() => {
new Alert("", mes, Language.StringByID(StringId.Close)).Show();
});
}
///
///
///
///
///
public static void ShowTip(String mes, View bodyView)
{
var tip = new Tip()
{
Text = mes,
CloseTime = 1,
Direction = AMPopTipDirection.None
};
tip.Show(bodyView);
}
#region ■ 各种正则检测_______________________
///
/// 用于中国大陆验证手机号正则表达式
///
public static string PhoneRegexStr = "^[1][0-9]{10}$";
///
/// 用于验证非中国大陆手机号正则表达式
///
public static string PhoneForForeignRegexStr = "^[0-9]*$";
///
/// 用于验证邮箱正则表达式
///
public static string EmailRegexStr = "^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$";
///
/// 判断是否包含大写字母
///
/// true, if contain upper was checked, false otherwise.
/// Value.
public static bool CheckContainUpper(string value)
{
Regex reg = new Regex("[A-Z]+");
return reg.IsMatch(value);
}
///
/// 判断是否包含小写字母
///
/// true, if contain lower was checked, false otherwise.
/// Value.
public static bool CheckContainLower(string value)
{
Regex reg = new Regex("[a-z]+");
return reg.IsMatch(value);
}
///
/// 判断是否包含数字
///
/// true, if contain lower was checked, false otherwise.
/// Value.
public static bool CheckContainNum(string value)
{
Regex reg = new Regex("[0-9]+");
return reg.IsMatch(value);
}
///
/// 判断是否包含符号
///
/// true, if contain lower was checked, false otherwise.
/// Value.
public static bool CheckContainSymbol(string value)
{
Regex reg = new Regex("([^a-z0-9A-Z])+");
return reg.IsMatch(value);
}
///
/// 检测邮箱是否合法
///
///
///
public static bool CheckEmail(string email)
{
Regex reg = new Regex(EmailRegexStr);
return reg.IsMatch(email);
}
///
/// 检测手机号是否合法
///
/// 手机号
/// 地区代码
///
public static bool CheckPhoneNumber(string phoneNumber, string areaCode)
{
//校验外国手机号
if (areaCode != "86")
{
Regex reg = new Regex(PhoneForForeignRegexStr);
return reg.IsMatch(phoneNumber);
}
//校验国内手机号
if (phoneNumber.Length > 11)
{
return false;
}
else if (phoneNumber.Length == 11)
{
Regex reg = new Regex(PhoneRegexStr);
return reg.IsMatch(phoneNumber);
}
else
{
//正则表达式判断是否数字
Regex reg = new Regex("^[0-9]*$");
return reg.IsMatch(phoneNumber);
}
}
#endregion
}
}