I want to check the input if there is a validate emailadress. This is the function I use
function validateEmailAddress(input) {
var regex = /[^\s@]+@[^\s@]+\.[^\s@]+/;
if (regex.test(input)) {
return 1;
} else if (regex.test(input) == null || regex.test(input) == ("")) {
return 0;
} else {
return -1;
}
}
This function is used there
savePerson: function () {
$('#accountid').prop('disabled', false);
let email = $('#emailaddresses').val();
if (validateEmailAddress(email) == -1) {
alert("This email isn't validate");
return;
}
So I have to check if the input field is empty. If this is happening, the data should be validate. If the inputfield isn't an emailaddress like "dasfasf232" it has to show an alert. Only if the email is valid (like it includes an @ and a dot). At the moment I get an alert when the emailfield is empty. But that should not happen.