微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jQuery验证表单远程规则,成功消息

我正在使用 jquery验证我的注册表单,它工作得很好,但我遇到了问题.我检查电子邮件是否存在,如果电子邮件确实存在,我收到错误消息.现在我想编辑这个,所以,如果电子邮件是免费使用的话.错误消息将更改为:此电子邮件可以免费使用.
$(document).ready(function(){
    $("#registratieform").validate({
        rules: {
            email: {
                required: true,email: true,remote: {
                    url: "includes/check_email.PHP",type: "post",complete: function(data){
                        if( data.responseText == "false" ) {
                            alert("Free");
                          }
                     }
                },},messages: {
            email: {
                required: "This field is required",email: "Please enter a valid email address",remote: jQuery.format("{0} is already taken")
            },});
});

警报有效,但此消息必须出现在错误所在的标签中.这可能吗?

解决方法

@Ruub:
远程消息应该是一个函数,而远程消息在规则中只是一个用于检查的URL
例:
$("#registratieform").validate({
    rules: {
        email: {
            required: true,remote: "includes/check_email.PHP"                    
        }
    },messages: {
        email: {
            required: "This field is required",remote: function() { return $.validator.format("{0} is already taken",$("#email").val()) }
        },});

在服务器端(includes / check_email.PHP):

if (!isValidEmail($_REQUEST['email'])) {
        echo "false";
        exit;
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐