Good day,
I am quite new to using forms and joomla, and don't have to much coding experience, can you please assist me with the following.
I would like to validate a number field with the following function, how must I go about it so that the form don't submit unless the number is validated against the custom js.
var generateLuhnDigit = function(inputString) {
var total = 0;
var count = 0;
for (var i = inputString.length-1; i >= 0; i--) {
var multiple = count % 2 + 1;
count++;
total += multiple * +inputString[i];
}
total = (total * 9) % 10;
return total;
}
var checkIDNumber = function(idNumber) {
var number = idNumber.substring(0, idNumber.length - 1);
return generateLuhnDigit(number) === +idNumber[idNumber.length - 1];
}
var result = {};
result.valid = checkIDNumber(idNumber);
return result;
}
Thank You
Corne
I am quite new to using forms and joomla, and don't have to much coding experience, can you please assist me with the following.
I would like to validate a number field with the following function, how must I go about it so that the form don't submit unless the number is validated against the custom js.
var generateLuhnDigit = function(inputString) {
var total = 0;
var count = 0;
for (var i = inputString.length-1; i >= 0; i--) {
var multiple = count % 2 + 1;
count++;
total += multiple * +inputString[i];
}
total = (total * 9) % 10;
return total;
}
var checkIDNumber = function(idNumber) {
var number = idNumber.substring(0, idNumber.length - 1);
return generateLuhnDigit(number) === +idNumber[idNumber.length - 1];
}
var result = {};
result.valid = checkIDNumber(idNumber);
return result;
}
Thank You
Corne
In a Custom JS block with the DOM ready box ticked, set up your function like this
In the "validation rules" for your field, put
jQuery.fn.form.settings.rules.myFunction= function(value){Replace the code with your own code.
if(value){
return true;
}
else{
return false;
}
};
In the "validation rules" for your field, put
myFunction:Message to display if validation failed
This topic is locked and no more replies can be posted.