codinasion-archive / codinasion-programme

An open source codebase for sharing programming solutions.
https://codinasion.vercel.app/programme
MIT License
62 stars 147 forks source link

Write a C# programme to check a valid email address #1262

Closed codinasion-bot[bot] closed 2 years ago

codinasion-bot[bot] commented 2 years ago

Description

Write a programme to check a valid email address


A valid email address consists of an email prefix and an email domain, both in acceptable formats.

The prefix appears to the left of the @ symbol.

The domain appears to the right of the @ symbol.

Acceptable email prefix formats

Invalid email address Valid email address
abc-@mail.com abc-d@mail.com
abc..def@mail.com abc.def@mail.com
.abc@mail.com abc@mail.com
abc#def@mail.com abc_def@mail.com
fadyfayek11 commented 2 years ago
    private static bool IsValid(string email)
    { 
        string regex = @"^[^@\s]+@[^@\s]+\.(com|net|org|gov)$";

        return Regex.IsMatch(email, regex, RegexOptions.IgnoreCase);
    }
harshraj8843 commented 2 years ago

Hey @fadyfayek11

Could you please raise a PR for this 👍🏻