Forum Replies Created
- AuthorPosts
pajura
Participant–
pajura
Participantsent via e-mail!
pajura
Participanthere is a piece of code that works with the above script to validate a “Romanian Personal Number” CNP as you type
// check valid CNP as we type
$.validator.addMethod("roCNP", function(value, element) {
var check = false;
var re = /^\d{1}\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])(0[1-9]|[1-4]\d| 5[0-2]|99)\d{4}$/;
if( re.test(value)) {
var bigSum = 0, rest = 0, ctrlDigit = 0;
var control = '279146358279';
for (var i = 0; i < 12; i++) {
bigSum += value[i] * control[i];
}
ctrlDigit = bigSum % 11;
if ( ctrlDigit == 10 ) ctrlDigit = 1;if ( ctrlDigit != value[12] ) return false;
else return true;} return false;
},
"CNP invalid"
);$('.iphorm-form-1').validate({ // initialize the validation
rules: {iphorm_1_1: { //CNP
required: true,
// number: true,
roCNP: true
}}
});
the script needs to enqueued in WP and the above code added in a .js file
pajura
ParticipantYes, silly me!
Thanks!pajura
ParticipantI use this http://jqueryvalidation.org/ to validate a field as is typed.
But to actually be validated once more during submit I recreated the validation with custom validation in PHP.
pajura
ParticipantThank you for your reply.
I did spend some time using jquery to validate fields one by one from one “page” to another but it is not very friendly.Hopefully in the future version!
- AuthorPosts