I am trying to validate an email address when the submit email button is pressed.
I tried adding JQuery validation to no avail. I was wondering how I could add an "if" statement that will just check and inform the user, that it is not a valid email in the same label that states it is sending an email.
$('#Submit').on("click", function () {
result = '<label style="color:white;">Sending message ...</label>';
$("#sendSuccess").html(result);
var email = $("#email").val();
var body = "From: " + name + "<br /> Email: " + email + "<br /> Message: " + message;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "EmailService.asmx/SendMail",
data: '{ body: "' + body + '", subject: "' + subject + '"}',
dataType: "json",
async: true,
success: function (data, status, xhr) {
//alert('success');
result = '<label style="color:green;">The message has been sent!</label>';
$("#sendSuccess").html(result);
},
error: function (data, status, xhr) {
//alert('fail');
result = '<label style="color:red;">The message has failed to send!</label>';
$("#sendSuccess").html(result);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<div>
<input id="email" type="text" name="email" class="form-control" />
</div>
<div>
<button type="submit" id="Submit" class="form-control">Click</button>
</div>
</html>