Chào mừng đến với Diễn Đàn Tin Học VN! Hãy chia sẽ những gì bạn biết, và đưa ra thắc mắc của bạn để được giải đáp.

Xem chủ đề cũ hơnGo downXem chủ đề mới hơn
phoenix51706
phoenix51706
Admin
Tổng số bài gửi : 171
Join date : 30/07/2010
https://diendantinhocvn.forumvi.com

jquery submit form cùng với validation Empty jquery submit form cùng với validation

13/03/22, 04:01 pm
script

Code:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.1/jquery.validate.min.js"></script>

<script>
    $(function() {
        $("#form_register").validate({
            rules: {
                "username": {
                    required: true,
                    minlength: 6,
                    maxlength: 12,
                    alpha_numericRegex: true
                },
                "password": {
                    required: true,
                    minlength: 6,
                    maxlength: 20,
                },
                "confirm_password": {
                    required: true,
                    minlength: 6,
                    maxlength: 20,
                    equalTo: password,
                },
                "full_name": {
                    required: true
                },
                "email": {
                    required: true,
                    maxlength: 200,
                    email: true
                },
                "contact": {
                    required: true,
                    minlength: 8,
                    maxlength: 20
                }
            },
            messages: {
                "username": {
                    required: "Vui lòng điền tên đăng nhập",
                    minlength: "Vui lòng nhập ít nhất {0} ký tự",
                    maxlength: "Vui lòng nhập tối đa {0} ký tự",
                    alpha_numericRegex:"Chỉ nhập ký tự chữ và số"
                },
                "password": {
                    required: "Vui lòng điền mật khẩu",
                    minlength: "Vui lòng nhập ít nhất {0} ký tự",
                    maxlength: "Vui lòng nhập tối đa {0} ký tự"
                },
                "confirm_password": {
                    required: "Vui lòng điền xác nhận mật khẩu",
                    minlength: "Vui lòng nhập ít nhất {0} ký tự",
                    maxlength: "Vui lòng nhập tối đa {0} ký tự",
                    equalTo: "Mật khẩu xác nhận phải trùng khớp với mật khẩu"
                },
                "full_name": {
                    required: "Vui lòng điền đầy đủ họ và tên"
                },
                "email": {
                    required: "Vui lòng điền email",
                    maxlength: "Vui lòng nhập tối đa {0} ký tự",
                    email: "Vui lòng điền email hợp lệ, ví dụ: example@mailtest.com",
                },
                "contact": {
                    required: "Vui lòng điền thông tin liên hệ",
                    minlength: "Vui lòng nhập ít nhất {0} ký tự",
                    maxlength: "Vui lòng nhập tối đa {0} ký tự"
                }
            },
            submitHandler: function() {
                $.ajax( {
                    type: "POST",
                    url: 'https://diendantinhocvn.com/dang-ky',
                    data: $("#form_register").serialize(),
                    success: function(data)
                    {
                            alert("Đăng ký thành công");              
                            window.location.href = "https://diendantinhocvn.com";                          
                      
                    }
                });

            }

        });
        
    });
    $.validator.addMethod("alpha_numericRegex", function (value, element) {
        return this.optional(element) || /^[a-z0-9\-]+$/i.test(value);
    });

</script>
Xem chủ đề cũ hơnVề Đầu TrangXem chủ đề mới hơn
Permissions in this forum:
Bạn không có quyền trả lời bài viết