This article mainly introduces C # common regular validation http://www.php.cn/wiki/145.html "target=" _blank "> function, an example of C # for IP authentication, price verification and positive integer verification of the relevant operational skills, A friend you need can refer to the following
The examples in this paper describe C # common regular validation functions. Share to everyone for your reference, as follows:
1. IP Address Verification
<summary>///IP Address authentication///</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. Price verification
<summary>///Price Verification///</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, positive integer verification
<summary>///positive integer validation//</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;}