using System;
|
using System.Linq;
|
using System.Text.RegularExpressions;
|
|
namespace Shared
|
{
|
public class CommonUtlis
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 通用方法
|
/// </summary>
|
private static CommonUtlis m_Current = null;
|
/// <summary>
|
/// 通用方法
|
/// </summary>
|
public static CommonUtlis Current {
|
get {
|
if (m_Current == null) {
|
m_Current = new CommonUtlis ();
|
}
|
return m_Current;
|
}
|
}
|
|
#endregion
|
|
#region ■ 各种正确检测_______________________
|
|
/// <summary>
|
/// 用于中国大陆验证手机号正则表达式
|
/// </summary>
|
public static string PhoneRegexStr = "^[1][0-9]{10}$";
|
/// <summary>
|
/// 用于验证非中国大陆手机号正则表达式
|
/// </summary>
|
public static string PhoneForForeignRegexStr = "^[0-9]*$";
|
/// <summary>
|
/// 用于验证邮箱正则表达式
|
/// </summary>
|
public static string EmailRegexStr = "^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$";
|
/// <summary>
|
/// 用于密码强度正则表达式
|
/// 密码必须为8-20个字符,包含字母、数字和符号
|
/// </summary>
|
//public static string PasswordRegexStr = "^(?![0-9]+$)(?![a-zA-Z]+$)(?![0-9a-zA-Z]+$)(?![0-9\\W]+$)(?![a-zA-Z\\W]+$)[0-9A-Za-z\\W]{8,20}$";
|
public static string PasswordRegexStr = @"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^\w\s]).{8,20}$";//必须包含一个大写,一个小写字母,一个数字,一个特殊字符,且长度为8到20位
|
|
|
|
|
/// <summary>
|
/// 判断是否包含大写字母
|
/// </summary>
|
/// <returns><c>true</c>, if contain upper was checked, <c>false</c> otherwise.</returns>
|
/// <param name="value">Value.</param>
|
public bool CheckContainUpper (string value)
|
{
|
Regex reg = new Regex ("[A-Z]+");
|
return reg.IsMatch (value);
|
}
|
|
/// <summary>
|
/// 判断是否包含小写字母
|
/// </summary>
|
/// <returns><c>true</c>, if contain lower was checked, <c>false</c> otherwise.</returns>
|
/// <param name="value">Value.</param>
|
public bool CheckContainLower (string value)
|
{
|
Regex reg = new Regex ("[a-z]+");
|
return reg.IsMatch (value);
|
}
|
|
/// <summary>
|
/// 判断是否包含数字
|
/// </summary>
|
/// <returns><c>true</c>, if contain lower was checked, <c>false</c> otherwise.</returns>
|
/// <param name="value">Value.</param>
|
public bool CheckContainNum (string value)
|
{
|
Regex reg = new Regex ("[0-9]+");
|
return reg.IsMatch (value);
|
}
|
|
/// <summary>
|
/// 判断是否包含符号
|
/// </summary>
|
/// <returns><c>true</c>, if contain lower was checked, <c>false</c> otherwise.</returns>
|
/// <param name="value">Value.</param>
|
public bool CheckContainSymbol (string value)
|
{
|
Regex reg = new Regex ("([^a-z0-9A-Z])+");
|
return reg.IsMatch (value);
|
}
|
|
/// <summary>
|
/// 检测邮箱是否合法
|
/// </summary>
|
/// <param name="email"></param>
|
/// <returns></returns>
|
public bool CheckEmail (string email)
|
{
|
Regex reg = new Regex (EmailRegexStr);
|
return reg.IsMatch (email);
|
}
|
|
/// <summary>
|
/// 检测手机号是否合法
|
/// </summary>
|
/// <param name="phoneNumber">手机号</param>
|
/// <param name="areaCode">地区代码</param>
|
/// <returns></returns>
|
public 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);
|
}
|
}
|
|
/// <summary>
|
/// 检测密码是否合法
|
/// </summary>
|
/// <param name="password"></param>
|
/// <returns></returns>
|
public bool CheckPassword (string password)
|
{
|
Regex reg = new Regex (PasswordRegexStr);
|
return reg.IsMatch (password);
|
}
|
|
#endregion
|
|
/// <summary>
|
/// 检测iOS是否越狱和Android是否root
|
/// </summary>
|
public void CheckIfJailBreak ()
|
{
|
|
#if __IOS__
|
var mes = "Your phone has been Jailbroken and you cannot use the APP.";
|
#else
|
var mes = "Your phone has been ROOT and you cannot use the APP.";
|
#endif
|
|
if (Shared.HDLUtils.ISJailBreak ()) {
|
|
Alert alert = new Alert ("", mes, Language.StringByID (SimpleControl.R.MyInternationalizationString.Confrim));
|
alert.ResultEventHandler += (sender2, e2) => {
|
Shared.HDLUtils.ExitApplication ();
|
};
|
alert.Show ();
|
}
|
|
|
}
|
|
/// <summary>
|
/// 弹窗提示
|
/// </summary>
|
/// <param name="mes">弹窗提示信息</param>
|
/// <param name="okAction">确认按钮事件</param>
|
public void ShowActionAlert (string mes, Action okAction)
|
{
|
Alert alert = new Alert ("", mes, Language.StringByID (SimpleControl.R.MyInternationalizationString.Cancel), Language.StringByID (SimpleControl.R.MyInternationalizationString.Confrim));
|
alert.ResultEventHandler += (sender2, e2) => {
|
if (e2) {
|
okAction?.Invoke ();
|
}
|
};
|
alert.Show ();
|
}
|
|
|
}
|
}
|