zoukankan      html  css  js  c++  java
  • c# 验证

    public class RegularExpressionsHelper
        {
            /// <summary>
            /// 对用户名进行格式进行检查的正则表达式
            /// </summary>
            /// <param name="userName">输入的用户名</param>
            /// <returns>验证结果</returns>
            public static bool UserNameRegex(string userName)
            {
                string nameRegex = @"^[0-9a-zA-Z_-]{6,16}$";
                return Regex.IsMatch(userName, nameRegex);
            }
    
            /// <summary>
            /// 验证手机号的正则表达式
            /// </summary>
            /// <param name="mobilePhoneNumber">输入的手机号</param>
            /// <returns>验证结果</returns>
            public static bool MobilePhoneNumberRegex(string mobilePhoneNumber)
            {
                string phoneNumberRegex = @"^1[3578]d{9}$";
                return Regex.IsMatch(mobilePhoneNumber, phoneNumberRegex);
            }
    
            /// <summary>
            /// 对邮箱进行验证的正则表达式
            /// </summary>
            /// <param name="emial">输入的邮箱</param>
            /// <returns>验证结果</returns>
            public static bool EmailRegex(string emial)
            {
                string emailRegex = @"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$";
                return Regex.IsMatch(emial, emailRegex); ;
            }
    
            /// <summary>
            /// 判断输入发字符串是否为GUID
            /// </summary>
            /// <param name="guid">输入的字符串</param>
            /// <returns>验证结果</returns>
            public static bool GuidRegex(string guid)
            {
                string guidRegex = @"^[a-fA-F0-9]{8}-([a-fA-F0-9]{4}-){3}[a-fA-Z0-9]{12}$";
                return Regex.IsMatch(guid, guidRegex);
            }
    
            /// <summary>
            /// 判断输入的字符串时候为车牌号
            /// </summary>
            /// <param name="carNumber">输入的字符串</param>
            /// <returns>验证结果</returns>
            public static bool CarNumReges(string carNumber)
            {
                string carNumReges = @"^[u4E00-u9FA5][A-Za-z][dA-za-z]{5}$";
                return Regex.IsMatch(carNumber, carNumReges);
            }
        }
  • 相关阅读:
    error: conflicting type qualifiers for &#39;xxxxx&#39;
    每天进步一点点——负载均衡之DNS域名解析
    hdu 1348 Wall(凸包模板题)
    offsetTop和scrollTop的差别
    OnContextMenu事件
    写给即将面临毕业的程序猿们
    hibernate uniqueResult方法
    UpdatePanel的用法
    Spring MVC 3 深入总结
    优麒麟(UbuntuKylin)不是国产Linux操作系统
  • 原文地址:https://www.cnblogs.com/liuqiyun/p/10910223.html
Copyright © 2011-2022 走看看