This validation is working only when i remove @ or . from the mail when i changed to com to hom,jom anything it is accepting how to correct this validation..

bool isEmail = Regex.IsMatch(TextBox4.Text.Trim(), @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
if (!isEmail)
{
lblerrormsg.Text = "Enter Valid Email ID..";
lblerrormsg.ForeColor = System.Drawing.Color.Red;
return;
}
else
{
lblerrormsg.Text = "Valid Email";
lblerrormsg.ForeColor = System.Drawing.Color.Green;
}
i used this one also
@"^[a-zA-Z][\w\.-]{0,68}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
Naimish MakwanaPosted Mar 6, 2023, 11:20 AM
Hello Jaya,
The regular expression pattern you are using to validate email addresses appears to be correct, as it matches the standard format for an email address.
It sounds like you are able to bypass the email validation by simply changing the domain name to something that doesn't end in ".com". This could happen if you are not enforcing a specific set of valid domain names.
One approach you can take to improve the validation is to create a list of valid top-level domains (TLDs) and only accept email addresses that end in one of those TLDs. For example, you could only accept email addresses that end in ".com", ".net", ".org", etc.
You can modify the regular expression pattern to include this check by replacing the last
The updated regular expression pattern would look like this:
\w+([-+.']\w+)*@\w+([-.]\w+)*.(com|net|org|edu|gov|mil|biz|info|name|museum|us|ca|uk|au|nz|asia|eu|int|pro|coop|aero|jobs|mobi|travel|tel|xxx)$This should help to ensure that only valid email addresses are accepted by your validation function.
Thanks
Naimish Makwana
Jaya PrakashPosted Mar 7, 2023, 10:20 AM
EoM0wwnG6NSsCN9fPg4YXyIf79nck/ot