when i click on submit data stored in database but that email user Enter in form so i want to send a email notification on that email..
if email is invalid so give a alert message Email Invalid. please help community......Thank you
Loading
when i click on submit data stored in database but that email user Enter in form so i want to send a email notification on that email..
if email is invalid so give a alert message Email Invalid. please help community......Thank you
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Abhishek ChadhaRank #402 · 6.2K reputationPosted May 17, 2024, 1:42 PM EDT
check with regex if the email is valid or not
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; // Example usage: const email = "[email protected]"; if (emailRegex.test(email)) { console.log("Valid email address"); } else { console.log("Invalid email address"); }you can pass the entered email to const email
Prasad RaveendranRank #320 · 7.8K reputationPosted May 17, 2024, 2:58 PM EDT
I would request you to provide the technology which you have been using to develop the Front end and sevices so that we can provide appropriate solution/suggestions
if you are using .NET 6.0 , in API, you can provide the below code at model level
[Required(ErrorMessage = "Email is required.")] [EmailAddress(ErrorMessage = "Invalid email address.")] public string Email { get; set; }the
[EmailAddress]data annotation attribute is available in .NET 6.0. This attribute is used to validate that a property contains a valid email address.in service endpoint, you can validate the model as below
if (!ModelState.IsValid) { ErrorMessage = "Email Invalid"; return; }Hope this may help
Jaimin ShethiyaRank #177 · 13.7K reputationPosted May 18, 2024, 9:13 AM EDT
Hello Soheb,
If you want to just email address is valid or not then you need to check with below code.
public bool IsValidEmail(string email) { var trimmedEmail = email.Trim(); if (trimmedEmail.EndsWith(".")) return false; try { var addr = new System.Net.Mail.MailAddress(email); return addr.Address == trimmedEmail; } catch { return false; } }If you want to check with ReGex then you need to use below code.
public static bool IsValidEmailUsingRegex(string email) { // Regular expression pattern for a valid email address string pattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"; return Regex.IsMatch(email, pattern); }or if you want to check the user has provided email address is correct or not then you need to please refer below links for validate.
https://verifalia.com/validate-email
https://hunter.io/email-verifier
https://www.neverbounce.com/email-verification
Thanks
Jayraj ChhayaRank #304 · 8.2K reputationPosted May 17, 2024, 6:27 AM EDT
To achieve this functionality in a .NET application, you can use the
SmtpClientclass from theSystem.Net.Mailnamespace to send an email notification. First, validate the email address using regular expressions or built-in .NET methods. If the email is valid, send the email; otherwise, display an alert message.using System.Net.Mail; string userEmail = "[email protected]"; // Get this from the form input MailMessage mail = new MailMessage("[email protected]", userEmail); SmtpClient client = new SmtpClient("smtp.yourserver.com"); try { client.Send(mail); // Email sent successfully } catch (Exception ex) { // Handle any exceptions (e.g., invalid email address) Console.WriteLine("Email sending failed: " + ex.Message); }Remember to replace
"[email protected]","smtp.yourserver.com", and the email validation logic according to your application requirements.