Validate Leading Zeros in Multi-Line String
- This topic has 2 replies, 2 voices, and was last updated 3 years, 10 months ago by .
Viewing 2 reply threads
Viewing 2 reply threads
- You must be logged in to reply to this topic.
Home › Forums › Classic DFFS › Validate Leading Zeros in Multi-Line String
I have a multi-line text field where users will enter any number of 5 digit client codes separated by “,”. I would like to validate the user includes any leading zeros in the list (“00003, 00023, 00007” vs. “3, 23, 7”). Any thoughts on how this might be done?
Thanks!
You can add a function like this to your Custom JS:
function customNumberPadding(fin){
jQuery("#dffs_"+fin+" :input").on("blur", function(){
var val = getFieldValue(fin);
var arr = val.split(",");
var newValArr = arr.map(v => {
return v.trim().padStart(5, "0");
});
setFieldValue(fin, newValArr.join(","));
});
}
customNumberPadding("Name_of_your_field");
Change “Name_of_your_field” to match the internal name of your field.
Please note that this code expects the textarea to only contain numbers and no additional text.
Alexander
Thank you!