mardi 10 décembre 2019

If statement - email validation/check

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;
        }

I think the problem is this "regex.test(input) == (" "))" because the function isn't checking if the input field it is empty. 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.

Aucun commentaire:

Enregistrer un commentaire