Bank Account Number Validation on an Amendment Request
As part of Klevr CE, we have an entity called Amendment Request which can be completed by an end user to update their bank account details.
Design Details
As part of Klevr CE, we have an entity called Amendment Request which can be completed by an end user to update their bank account details. This will follow an approval process (either in CE or BC) before the data is then updated on their actual account record. The bank account details need to be captured in the correct format, and as such, the following script was developed to evaluate and format the bank account numbers on the portal.
It assumes you have 3 fields on the form: the country lookup selector, the BSB number, and the Account number. It will check if the country is Australia and hide/show the BSB number field. It will also adjust the formatting and evaluation of the bank account number field accordingly. This script supports Australian and New Zealand formats, but can be extended to support other formats too.
Copy the code to a new script file, upload it to the media section in Umbraco, and add it to the amendment request page. (This requires portal version 2.1.0 to work)
Code:
//bank account validations
function hideshowBSB() {
if (dFormApp.$data.klevr_countryid.name != "Australia") {
$("#klevr_bankstatebranchnumber").parent().hide();
} else {
$("#klevr_bankstatebranchnumber").parent().show();
}
}
hideshowBSB();
$("#klevr_countryid").change(hideshowBSB);
klevrValidators.push({
field: "klevr_bankstatebranchnumber",
func: function (el) {
var regex = new RegExp("^\\d{2}-\\d{4}$");
if (!regex.test(el) && $("#klevr_bankstatebranchnumber").is(":visible")) return "Please enter the number in the format xx-xxxx";
else return "";
}
});
klevrValidators.push({
field: "klevr_bankaccountnumber",
func: function (el) {
if ($("#klevr_bankstatebranchnumber").is(":visible")) {
var regex = new RegExp("^\\d{7,8}-\\d{2,3}$");
if (!regex.test(el)) return "Please enter the number in the format xxxxxxxx-xx";
else return "";
} else {
var regex = new RegExp("^\\d{2}-\\d{4}-\\d{7,8}-\\d{2,3}$");
if (!regex.test(el)) return "Please enter the number in the format xx-xxxx-xxxxxxxx-xx";
else return "";
}
}
});
$("#klevr_bankaccountnumber").keyup(()=> {
var el = dFormApp.$data.klevr_bankaccountnumber;
if ($("#klevr_bankstatebranchnumber").is(":visible")) {
if (el.length == 8 && el.indexOf("-") == -1) dFormApp.$data.klevr_bankaccountnumber = el + "-";
} else {
if (el.length == 2 && el.indexOf("-") == -1) dFormApp.$data.klevr_bankaccountnumber = el + "-";
if (el.length == 7 && el.indexOf("-", 3) == -1) dFormApp.$data.klevr_bankaccountnumber = el + "-";
if (el.length >= 16 && el.indexOf("-", 9) == -1) dFormApp.$data.klevr_bankaccountnumber = el + "-";
}
});
$("#klevr_bankstatebranchnumber").keyup(()=> {
var el = dFormApp.$data.klevr_bankstatebranchnumber;
if (el.length == 2 && el.indexOf("-") == -1) dFormApp.$data.klevr_bankstatebranchnumber = el + "-";
});Last updated on