Validate Leading Zeros in Multi-Line String

Forums Dynamic Forms for SharePoint Validate Leading Zeros in Multi-Line String

Viewing 2 reply threads
  • Author
    Posts
    • #36304
      Rick Cedergren
      Participant

      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!

    • #36306
      Alexander Bautz
      Keymaster

      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

    • #36309
      Rick Cedergren
      Participant

      Thank you!

Viewing 2 reply threads
  • You must be logged in to reply to this topic.