RegularExpressions









How do I use Regular Expressions
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: frmCustomerRegistration.cs Copy
168         private void Email_Address_Validating(object sender, CancelEventArgs e)
169         {
170             System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
171             if (txtEmail_Address.Text.Length > 0)
172             {
173                 if (!rEMail.IsMatch(txtEmail_Address.Text))
174                 {
175                     MessageBox.Show("invalid email address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
176                     txtEmail_Address.SelectAll();
177                     e.Cancel = true;
178                 }
179             }
180         }
File name: frmCustomerRegistration.cs Copy
187         private void Username_Validating(object sender, CancelEventArgs e)
188         {
189             System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex("^[a-zA-Z0-9_]");
190             if (txtUsername.Text.Length > 0)
191             {
192                 if (!rEMail.IsMatch(txtUsername.Text))
193                 {
194                     MessageBox.Show("only letters,numbers and underscore is allowed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
195                     txtUsername.SelectAll();
196                     e.Cancel = true;
197                 }
198             }
199         }
File name: frmRegistration.cs Copy
193         private void Email_Address_Validating(object sender, CancelEventArgs e)
194         {
195             System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
196             if (txtEmail_Address.Text.Length > 0)
197             {
198                 if (!rEMail.IsMatch(txtEmail_Address.Text))
199                 {
200                     MessageBox.Show("invalid email address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
201                     txtEmail_Address.SelectAll();
202                     e.Cancel = true;
203                 }
204             }
205         }
File name: frmRegistration.cs Copy
212         private void Username_Validating(object sender, CancelEventArgs e)
213         {
214             System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex("^[a-zA-Z0-9_]");
215             if (txtUsername.Text.Length > 0)
216             {
217                 if (!rEMail.IsMatch(txtUsername.Text))
218                 {
219                     MessageBox.Show("only letters,numbers and underscore is allowed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
220                     txtUsername.SelectAll();
221                     e.Cancel = true;
222                 }
223             }
224         }
File name: frmUpdateCustomerDetails.cs Copy
27         private void Email_Address_Validating(object sender, CancelEventArgs e)
28         {
29             System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
30             if (txtEmail_Address.Text.Length > 0)
31             {
32                 if (!rEMail.IsMatch(txtEmail_Address.Text))
33                 {
34                     MessageBox.Show("invalid email address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
35                     txtEmail_Address.SelectAll();
36                     e.Cancel = true;
37                 }
38             }
39         }
File name: frmUpdateCustomerDetails.cs Copy
46         private void Username_Validating(object sender, CancelEventArgs e)
47         {
48             System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex("^[a-zA-Z0-9_]");
49             if (txtUsername.Text.Length > 0)
50             {
51                 if (!rEMail.IsMatch(txtUsername.Text))
52                 {
53                     MessageBox.Show("only letters,numbers and underscore is allowed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
54                     txtUsername.SelectAll();
55                     e.Cancel = true;
56                 }
57             }
58         }

RegularExpressions 105 lượt xem

Gõ tìm kiếm nhanh...