I am doing validation of the registered user's email, and I want to display the message to him in case the email already exists, so I did this:
//validação de email
$(function validateEmail() {
$('#Email').change(function () {
var url = '@Url.Action("ValidateEmail", "Ajax")';//url do controller que passará a informação
var email = $('#Email').val();
$.ajax({
type: 'POST',
url: url,
data: { email: email },
dataType: 'json',
success: function (data) {
$('#MensagemEmail').append("Email Já Cadastrado");
$('#Email').focus();
},
error: function (data) {
$('#MensagemEmail').append("Email Disponível");
}
});
});
});//Fim da validação de email
My problem is that when the user enters 2 emails he already has, the message is duplicated as shown in the image below:
My question is how do I clear the value before inserting another one? because I tried to use $('#MensagemEmail').val('');
but it did not roll.