I can't get the logic of this problem from my mind. Will you help me, pls?
I make a manual email validation for practice. So, in email validation there's a validation that states: "@ is cannot be more than one."
I'm stuck from here:
int atValidation = 0;
for (int i = 0; i < txtEmail.Text.Length; i++)
{
if (Char.IsSymbol('@'))
{
atValidation++;
}
}
I'm sorry if my question is confusing, I can only explain like this vvv
Example:
Input Email |_______|
Input Email | rich@[email protected] |
message box: '@' cannot be more than one
Input Email | [email protected] |
message box: email is valid
There are many more rules for email validation, but if all you want to do is check for a single @ sign, you could get all of the @ characters and check the count
if (txtEmail.Text.ToCharArray().Where(x => x == '@').Count() != 1)
{
//email is invalid
}