How form form validation ajax submits data after validation

function addUser() {
    let data={}
    $.each($("-sharpaddUser").serializeArray(),function () {
        data[this.name]=this.value;
    })
    let userName=$("input[name="userName"]").val();
    let password=$("input[name="password"]").val();
    let password2=$("input[name="password2"]").val();
    let mobile=$("input[name="mobile"]").val();
    let remarks=$("input[name="remarks"]").val();
    let mobileReg=/^1[3|4|5|8][0-9]\d{4,8}$/i;
    if(userName.length==0){
        let formAlert=$("input[name="userName"]").next(".form-alert");
        formAlert.show();
        formAlert.html("");
    }
    if(password.length==0){
        let formAlert=$("input[name="password"]").next(".form-alert");
        formAlert.show();
        formAlert.html("");
    }
    if(password2.length==0){
        let formAlert=$("input[name="password2"]").next(".form-alert");
        formAlert.show();
        formAlert.html("");
    }else if(password2!==password){
        let formAlert=$("input[name="password2"]").next(".form-alert");
        formAlert.show();
        formAlert.html("");
    }
    if(remarks.length==0){
        let formAlert=$("input[name="remarks"]").next(".form-alert");
        formAlert.show();
        formAlert.html("");
    }
    if(mobile.length==0){
        let formAlert=$("input[name="mobile"]").next(".form-alert");
        formAlert.show();
        formAlert.html("");
    }else if(!mobileReg.test(mobile)){
        let formAlert=$("input[name="mobile"]").next(".form-alert");
        formAlert.show();
        formAlert.html("");
    }
    $.ajax({
        type : "POST",
        url : "/api/user/add",
        data :data,
        success : function(result) {
            $(".alert").show();
            if(result.msg==""){
                $(".alert").addClass("alert-success").removeClass("alert-danger");
            }
            $(".alert").text(result.msg);
            setTimeout(function () {
                $(".alert").hide();
            },3000)
            console.log(result)
        },
        error:function (result) {
            $(".alert").show();
            $(".alert").text(result.msg);
            setTimeout(function () {
                $(".alert").hide();
            },3000)
        }
    });
}

as in the above code, I wrote the form verification. How to ensure that after the verification is correct, then jump to ajax, and then jump directly to ajax


return where verification fails


is said upstairs, where verification is incorrect, directly return


ajax () can't be put in an if statement, write directly must be page refresh and execute.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e52904-451c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e52904-451c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?