Newbie to C# and seem to have an issue. Im amending a program that has the below code validating email address':
public static bool IsValidEmail(string sEmail)
{
sEmail = sEmail.Trim();
if (sEmail == string.Empty)
{
return false;
}
return (Regex.IsMatch(sEmail, @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
+ @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
+ @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
+ @"([a-zA-Z]+[\w-]*\.)+[a-zA-Z]{1,4})$"));
Now since this was implemented email validation has changed and now i want to only validate on there being an @ and a . in the address.
I tried:
public static bool IsValidEmail(string sEmail)
if ((sEmail.IndexOf("@") != -1) & (sEmail.IndexOf(".") != -1))
{
return true;
}
else
{
return false;
}
but a should be now valid address ie name+@domain.com is still being recieved as bad.
Any help would be appreciated.