如何以语义ui形式制作已经存在的电子邮件或用户名验证?

时间:2017-07-26 10:51:15

标签: javascript php semantic-ui

您好我是语义ui框架的新手,我希望像电子邮件已经存在或用户名已经存在验证。所以我正在做的事情我做了一个自定义规则并运行ajax检查电子邮件或用户名已经存在或者不....请检查以下代码。电子邮件已经存在

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;

}

但问题是Ajax正在运行每个单独输入的字母表,并且我想(对于特定字段)它应该首先由其他规则验证,然后自定义规则功能工作。所以我可以检查其他规则在自定义规则中有效吗

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

或者任何人都可以建议我如何进行验证,如电子邮件已经存在或用户名已经存在于语义ui表单中?

0 个答案:

没有答案