Cハハハ常用正則検証関数例


本論文の実例はC葃常用正則検証関数を述べている。皆さんに参考にしてあげます。具体的には以下の通りです。
1、Ipアドレス検証

/// <summary>
/// Ip    
/// </summary>
public static bool CheckIp(string ip)
{
  bool result = false;
  Regex ipReg = new Regex(@"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$");
  if (ipReg.IsMatch(ip))
  {
    result = true;
  }
  return result;
}

2、価格検証

/// <summary>
///     
/// </summary>
/// <param name="priceStr"></param>
/// <returns></returns>
public bool CheckPrice(string priceStr)
{
  bool result = false;
  Regex regex = new Regex(@"^\d+(\.\d{1,2})?$", RegexOptions.IgnoreCase);
  Match match = regex.Match(priceStr);
  if (match.Success)
  {
    result = true;
  }
  return result;
}

3、正の整数検証

/// <summary>
///      
/// </summary>
public static bool CheckPositiveInteger(string numStr)
{
  bool result = false;
  Regex regex = new Regex(@"^[1-9]\d*$", RegexOptions.IgnoreCase);
  Match match = regex.Match(numStr);
  if (match.Success)
  {
    result = true;
  }
  return result;
}

PS:ここでもう2つの非常に便利な正規表現ツールを提供します。
JavaScript正規表現はオンラインテストツールです。
http://tools.jb51.net/regex/javascript
正規表現のオンライン作成ツール:
http://tools.jb51.net/regex/create_reg
C˜関連の内容についてもっと興味がある読者は、当駅のテーマを見ることができます。「C氨正則表現の使い方のまとめ」、「C〓〓コードの操作の技巧は総括します」、「C〓中XMLファイルの操作技術のまとめ」、「C〓〓〓データ構造とアルゴリズム教程」、「C铅対象プログラム設計入門教程」および「C〓〓〓プログラムの設計のスレッドは技巧を使って総括します。
ここで述べたように、皆さんのC〓プログラムの設計に役に立ちます。