Jump to content

Recommended Posts

$("#btnRegister").click(function (e) {
        e.preventDefault();

        if (validateRegistration()) {
            calltest();

function validateRegistration() {
    var email = $("#txtEmail").val();
    var password = $("#txtPassword").val();
    var password2 = $("#txtPassword2").val();
    var isValid = false;
    var alertText = "";
    var genericAlert = '<div class="alert alert-danger alert-dismissible fade show" role="alert"><button type="button" ' +
        'class="close" data-dismiss="alert" aria-label="Close" aria-hidden="true">&times;</button>';

    // EMAIL VERIFICATION
    if (email != "") {
        var emailRegex = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
        if (email.match(emailRegex)) {
            isValid = true;
        } else {
            alertText = "Email is not in the correct format.";
            emailFormatAlert = genericAlert + alertText + '</div>';
            $("#alertArea").append(emailFormatAlert);
            isValid = false;
        }
    } else {    //alert("Email cannot be empty.");     + '</div>'
        alertText = "Email cannot be empty.";
        emailAlert = genericAlert + alertText + '</div>';
        $("#alertArea").append(emailAlert);
        isValid = false;
    }
    // PASSWORD VERIFICATION
    if (password != "") {
        if (password.length < 5) {
            $("#alertPass").show();
            isValid = false;
        } else {
            isValid = true;
        }
    } else {
        alertText = "Password cannot be empty.";
        passwordAlert = genericAlert + alertText + '</div>';
        $("#alertArea").append(passwordAlert);
        isValid = false;
    }
    // PASSWORD MATCH
    if (password != password2) {
        alertText = "Passwords do not match!";
        pass2Alert = genericAlert + alertText + '</div>';
        $("#alertArea").append(pass2Alert);
        isValid = false;
    } else {
        isValid = true;
    }

    return isValid;
}

Hello all,

My $.ajax() is running even when my validateRegistration() is invalid. My validateRegistration() is registering true wether its valid or invalid. Could someone look at this method and let me know if they see anything wrong with it.

It always returns TRUE I'm not sure why I stepped through the JS and the validregister() returns isvalid = false so why on the if(validreg()) it returns true... I have if(validreg()){alert("valid");}else{alert("Invalid");} Its always valid

function validate()
    isValid = true;

    if email is invalid 
        set isValid = false
    if password is invalid 
        set isValid = false
    if passwords do not match 
        set isValid = false

    return isValid
end

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.