程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#基礎知識 >> 常用正則表達式(C#)

常用正則表達式(C#)

編輯:C#基礎知識

/// <summary>
/// 身份證
/// </summary>
public static readonly string IDCard = @"^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$";

/// <summary>
/// 港澳通行證
/// </summary>
public static readonly string PassCard = @"^[HMhm]{1}([0-9]{10}|[0-9]{8})$";

/// <summary>
/// 護照
/// </summary>
public static readonly string Passport = @"^[a-zA-Z0-9]{5,17}$";

/// <summary>
/// 台胞證
/// </summary>
public static readonly string Taiwan =@"(^[0-9]{8}$)|(^[0-9]{10}$)";

/// <summary>
/// 手機號
/// </summary>
public static readonly string Mobile = @"^1\d{10}$";

/// <summary>
/// 航空公司二字碼
/// </summary>
public static readonly string AirlineCode = @"^[1-9a-zA-Z]{2}$";

/// <summary>
/// 艙位碼
/// </summary>
public static readonly string SeatCode = @"^[A-Z]{1}([0-9]{1})?(\,[A-Z]{1}([0-9]{1})?)*$";

/// <summary>
/// 機場三字碼或城市三字碼
/// </summary>
public static readonly string CityCode = @"^[a-zA-Z]{3}$";

/// <summary>
/// 只能為數字或字符串
/// </summary>
public static readonly string NumberOrLetter = @"^[A-Za-z0-9]+$";

/// <summary>
/// 驗證日期格式 yyyy-MM-dd
/// </summary>
public static readonly string Date = @"^\d{4}-\d{2}-\d{2}$";

/// <summary>
/// 只匹配0和1
/// </summary>
public static readonly string OnlyZeroOrOne = @"^[0-1]{1}$";

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved