Skip to content

Instantly share code, notes, and snippets.

@ThienTranDuy
Created November 4, 2020 10:12
Show Gist options
  • Save ThienTranDuy/e3ee81200515b52ba1e6152d39fdbf7b to your computer and use it in GitHub Desktop.
Save ThienTranDuy/e3ee81200515b52ba1e6152d39fdbf7b to your computer and use it in GitHub Desktop.
jquery validate email, phone, CMND, name, image
// allow domains
var allowDomains = ["gmail.com", "hotmail.com", "outlook.com"];
$.validator.addMethod('allowDomain', function(value, elem, param) {
var domain = value.split('@')[1];
return allowDomains.indexOf(domain) >= 0;
}, 'Định dạng mail chập nhận: @gmail.com, @hotmail.com, @outlook.com');
// validate form
$("#embedForm").validate({
ignore: ":hidden",
rules: {
bill_number: {
required: true,
minlength: 5
},
mg_34_field: {
required: true,
extension: "jpg|png|jpeg"
},
name: {
required: true,
minlength: 3
},
cmnd: {
required: true,
number: true,
maxlength: 12,
minlength: 9
},
email: {
required: true,
email: true,
allowDomain: true
},
phone: {
required: true,
number: true,
pattern: /((09|03|07|08|05)+([0-9]{8})\b)/
},
address: {
required: true,
}
},
messages: {
bill_number: {
required: "Vui lòng nhập mã hóa đơn",
minlength: "Độ dài mã hóa đơn phải lớn hơn 5 kí tự"
},
mg_34_field: {
required: "Vui lòng gửi ảnh hóa đơn",
extension: "Định dạng tệp đính kèm phải là .jpg hoặc .png"
},
name: {
required: "Vui lòng nhập họ và tên của bạn",
minlength: "Độ dài tên phải lớn hơn 3 kí tự"
},
cmnd: {
required: "Vui lòng nhập CMND",
number: "CMND phải là kí tự số",
maxlength: "Độ dài CMND phải lớn hơn 9 và bé hơn 12",
minlength: "Độ dài CMND phải lớn hơn 9 và bé hơn 12"
},
email: {
required: "Vui lòng nhập email của bạn",
},
phone: {
required: "Vui lòng nhập số điện thoại của bạn",
number: "Số điện thoại phải là kí tự số",
pattern: "Định dạng số điện thoại không hợp lệ"
},
address: {
required: "Vui lòng nhập địa chỉ nhận quà",
}
},
submitHandler: function(form,e) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment