sheikh-k
11/3/2016 - 1:15 PM

Regular Expressions (Basic - with WindowsForm).cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Regular_Expressions
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCheckAll_Click(object sender, EventArgs e)
        {
            //  mail@mail.com
            RegExp(@"^([\w]+)@([\w]+)\.([\w]+)$", txtEmail, LblEmailMessage, "Email");
            
            // http://www.google.com
            RegExp(@"^(http://www\.)([\w]+)\.([\w]+)$", TxtWebsite, LblWebsiteMessage, "Website");

            // Phone Number like : 0011 555 666 777
            RegExp(@"^(0011)(([ ][0-9]{3}){3})$", TxtPhone, LblPhoneMessage, "Phone Number");

            // 30/07/1993
            RegExp(@"^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$", TxtBirthDate, LblBirthDateMessage, "Birthday");
        }

         public void RegExp(string re,TextBox tb ,Label lb,string s)
         {
             Regex regex = new Regex(re);
             if (regex.IsMatch(tb.Text))
             {
                 lb.ForeColor = Color.Green;
                 lb.Text = s + " Valid";
             }
             else
             {
                 lb.ForeColor = Color.Red;
                 lb.Text = s + " InValid";
             }
         }
    }
}