.Net正则表达式的例子

1 例子一

 1 using System.Text.RegularExpressions;
 2 
 3 
 4 string strTempDistrictID = txtDistrictID.Text;
 5 
 6 //必须是[数字][数字][0000]格式
 7 Regex re = new Regex("^[0-9]{2}[0]{4}$");
 8 Match match = re.Match(strTempDistrictID);
 9 if (match.Success == false)
10 {
11     MessageBox.Show("地区代码(省份代码)必须是 \"前两位必须是数字,后四位必须是零\" 的格式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
12     txtDistrictID.Focus();
13     return false;
14 }
原文地址:https://www.cnblogs.com/YangBinChina/p/2965853.html