How to make a pre-existing email or username confirmation in ui semantics form?

Hi, I am new to ui semantic structure and I want to check if the email already exists or the username already exists. So what I do, I created my own rule and run ajax to check the email or username already existing or not .... Please check the below code. email already exists

email: {
    identifier: 'email',
    rules: [{
            type: 'email',
            prompt: 'Please enter a valid e-mail'
        },
        {
            type: 'alreadyExistemail',
            prompt: 'This email is already registered, please choose another one.'
        }
    ]
}
$.fn.form.settings.rules.alreadyExistemail = function(param) {
    return Check_existence(param);
}

function Check_existence(param) {
    //Here I am running ajax which is communicating with db and returning true or false.
     var a;
      $.ajax({
            method: "POST",
            url: ajax_url,
            async:false,
            data: { 'action': 'checkEmailalreadyexist','email':param},
            success: function (data) {
                a = data;
            }
        });
        return a;

}

      

But the problem is that Ajax works with each individual alphabet and I want (for a specific field) it must first be validated by another rule and then work with the custom rule functionality. so this is possible, I can test another rule in effect in a custom rule like

$.fn.form.settings.rules.alreadyExistemail = function(param) {
    if (is valid(email)) {
        return Check_existence(param);
    }
}

      

or can anyone suggest how I can make a check, for example, that the mail already exists or the username already exists in the semantic form ui?

+3


source to share





All Articles