How to make already exist email or username validation in semantic ui form?

Viewed 459

Hi I am new in semantic ui framework and I want to make the validation like email already exist or username already exist .so what I am doing I have made a custom rule and run the ajax for checking email or username already exist or not.... Please check bellow code ex. of email already exist

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 Problem is that Ajax is running with every single typed alphabet and I want (for specific field) it should first validated by other rule then custom rule functionality work. so is it possible I can check other rule valid in custom rule like that

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

or can any one please suggest how can I make validation like email already exist or username already exist in semantic ui form?

0 Answers
Related