Saturday, 31 October 2015

Write a Program in C# using Regular Expressions to read an Email from the user and validate it.

using System;
using System.Text.RegularExpressions;
class Program
{
    static void Main()
    {
        Console.WriteLine("Enter your email id");
        string email = Console.ReadLine();
        string regExpEmail= @"^((([\w]+\.[\w]+)+)|([\w]+))@(([\w]+\.)+)([A-Za-z]{1,3})$";

        if (Regex.IsMatch(email, regExpEmail))
        {
            Console.WriteLine("Email in Correct format");
        }
        else
        {
            Console.WriteLine("Invalid Email format");
        }
    }
}

No comments:

Post a Comment