@Sparky bir Hesap adı ve/veya Şifre güncellemesini doğrulamak için cevabınızı kullanmaya çalışıyorum. Ben orijinal Hesap Adı ve Şifre girin ve ardından güncelleme düğmesi ve özgün Hesap adının doğrulama tıklayıp Parola (yani hiçbir ileti, yeni bir hesap veya Şifre girilmesi gerektiğini söylemek) gerçekleştirilir. Benim kodum:
$(document).ready(function(){
$.validator.addMethod(
"regex",
function(value, element, regexp)
{
if (regexp.constructor != RegExp)
regexp = new RegExp(regexp);
else if (regexp.global)
regexp.lastIndex = 0;
return this.optional(element) || regexp.test(value);
},
"Please enter correct Characters."
);
jQuery.validator.addMethod("require_from_group", function (value, element, options) {
var numberRequired = options[0];
var selector = options[1];
var fields = $(selector, element.form);
var filled_fields = fields.filter(function() {
// it's more clear to compare with empty string
return $(this).val() != "";
});
var empty_fields = fields.not(filled_fields);
// we will mark only first empty field as invalid
if (filled_fields.length < numberRequired && empty_fields[0] == element) {
return false;
}
return true;
// {0} below is the 0th item in the options field
}, jQuery.format("'Please enter either a new Account name and/or a new password'/Please fill out at least {0} of these fields."));
$('[data-toggle="tooltip"]').tooltip();
$("#contactForm").validate({
groups: { // consolidate messages into one
names: "accountName1 enterPassword1"
},
rules: {
accountName: {
required: true,
minlength: 2
},
enterPassword: {
required: true,
minlength: 8
},
accountName1: {
require_from_group: [1, ".send"],
minlength: 2
},
accountName2: {
minlength: 2,
equalTo: "#accountName1"
},
enterPassword1: {
require_from_group: [1, ".send"],
regex: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[[email protected]$!%*?&])[A-Za-z\[email protected]$!%*?&]{8,}/,
minlength: 8
},
enterPassword2: {
regex: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[[email protected]$!%*?&])[A-Za-z\[email protected]$!%*?&]{8,}/,
minlength: 8,
equalTo: "#enterPassword1"
}
},
messages: {
accountName: {
required: "Please enter your current account name.",
minlength: "Your account name must consist of at least 2 characters."
},
enterPassword: {
required: "Please enter your current password.",
minlength: "Your password must consist of at least 8 characters."
},
accountName1: {
minlength: "Your account name must consist of at least 2 characters."
},
accountName2: {
minlength: "Your account name must consist of at least 2 characters.",
equalTo: "Your confirmation account name does not match the original."
},
enterPassword1: {
regex: "Please nter at least 8 characters containing at least 1 lower case, 1 upercase, 1 special and 1 numeric..",
minlength: "Your password must consist of at least 8 characters."
},
enterPassword2: {
regex: "Please enter at least 8 characters containing at least 1 lower case, 1 upercase, 1 special and 1 numeric..",
minlength: "Your password must consist of at least 8 characters.",
equalTo: "Your confirmation password does not match the original."
}
},
submitHandler : function(contactForm) {
//do something here
var frm = $('#contactForm');
//alert($("#accountName1").val());
$.ajax({
type: "POST",
url: "UpdateAccountView",
cache: false,
data: frm.serialize(),
success: function(data){
console.log('Submission was successful.');
console.log(data);
$("#accountName").focus();
$('#ajaxGetUserServletResponse').text(data);
}
});
}
});
}); // end document.ready
jQuery Validate eklentisini eklediniz mi? Eğer 'validator.addMethod()' kullandığınız için, bu jQuery doğrula eklentisi dahil ve düzgün yapılandırılmış olmasını gerektirir. – Sparky
Lütfen yinelenen sorular göndererek SO'yı kötüye kullanmayın: [JQuery-1.9.1.min] 'deki iki alandan birini (boş alan olarak) doğrulayın (http://stackoverflow.com/questions/15134832/validatein-terms -Kalan alan-herhangi bir-out-of-iki-alanları-in-jquery-1-9-1-min) – Sparky