| | |
| | | using System; |
| | | namespace HDL_ON.Common |
| | | using Shared; |
| | | using System.Text.RegularExpressions; |
| | | |
| | | namespace HDL_ON |
| | | { |
| | | /// <summary> |
| | | /// 常用工具类 |
| | | /// </summary> |
| | | public class Utlis |
| | | { |
| | | /// <summary> |
| | | /// 全局打印 |
| | | /// </summary> |
| | | public static void WriteLine(object mes) |
| | | /// <summary> |
| | | /// 全局打印 |
| | | /// </summary> |
| | | public static void WriteLine(object mes) |
| | | { |
| | | #if DEBUG |
| | | Console.WriteLine(mes); |
| | | #endif |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 弹窗提示 |
| | | /// </summary> |
| | | /// <param name="mes"></param> |
| | | public static void ShowAlertOnMainThread(string mes) |
| | | { |
| | | Application.RunOnMainThread(() => { |
| | | new Alert("", mes, Language.StringByID(StringId.Close)).Show(); |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ShowTip |
| | | /// </summary> |
| | | /// <param name="mes"></param> |
| | | /// <param name="closeTime">关闭时间</param> |
| | | public static void ShowTip(String mes, int closeTime = 2) |
| | | { |
| | | var tip = new Tip() |
| | | { |
| | | Text = mes, |
| | | CloseTime = closeTime, |
| | | Direction = AMPopTipDirection.None |
| | | }; |
| | | tip.Show(MainPage.BaseView); |
| | | } |
| | | |
| | | |
| | | #region ■ 各种正则检测_______________________ |
| | | /// <summary> |
| | | /// 用于中国大陆验证手机号正则表达式 |
| | | /// 以1开头,11位 |
| | | /// </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> |
| | | /// 判断是否包含大写字母 |
| | | /// </summary> |
| | | /// <returns><c>true</c>, if contain upper was checked, <c>false</c> otherwise.</returns> |
| | | /// <param name="value">Value.</param> |
| | | public static 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 static 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 static 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 static 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 static 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 static bool CheckPhoneNumber(string phoneNumber, string areaCode) |
| | | { |
| | | //校验外国手机号 |
| | | if (areaCode != "86") |
| | | { |
| | | Regex reg = new Regex(PhoneForForeignRegexStr); |
| | | return reg.IsMatch(phoneNumber); |
| | | } |
| | | else |
| | | { |
| | | //校验国内手机号 |
| | | Regex reg = new Regex(PhoneRegexStr); |
| | | return reg.IsMatch(phoneNumber); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// TextButton |
| | | /// 根据文本,计算按钮它实际的宽度 |
| | | /// </summary> |
| | | /// <param name="btn"></param> |
| | | /// <param name="extendWidth">补充宽度</param> |
| | | /// <returns></returns> |
| | | public static int GetRealWidthByTextButton(Button btn, int extendWidth = 1) |
| | | { |
| | | if (string.IsNullOrEmpty(btn.Text)) { return Application.GetRealWidth(extendWidth); } |
| | | |
| | | return btn.GetTextWidth() + Application.GetRealWidth(extendWidth); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据文本,计算按钮它实际的宽度 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static int GetRealWidthByText(Button btn) |
| | | { |
| | | if (string.IsNullOrEmpty(btn.Text)) { return Application.GetRealWidth(4); } |
| | | #if __IOS__ |
| | | //需要增加一个误差值 |
| | | return btn.GetTextWidth() + Application.GetRealWidth(8); |
| | | #else |
| | | //需要增加一个误差值 |
| | | return btn.GetTextWidth() + Application.GetRealWidth(4); |
| | | #endif |
| | | } |
| | | |
| | | } |
| | | |
| | | } |