Home > Blockchain >  How to change this script to have a max character limit instead of a min?
How to change this script to have a max character limit instead of a min?

Time:09-21

I am working on a form in Unbounce and need the name fields to have a max character limit. I found this script in the Unbounce community but can't seem to get the modifications to work for a max limit instead of a min. Can someone help me with what changes I need to make. Thanks!

<script>
  window.ub.form.customValidators.characterminlimit = {
    isValid: function(value) {
        return /^(?=.{50,})/.test(value);
    },
    message: 'Enter min 50 character',
  };
</script>

<script>
  window.ub.form.validationRules.first_name.characterminlimit = true;
</script>

CodePudding user response:

If for some reason you can't get the length for the string value, you can try this regex /(^.{1,50}$)/ instead of the one you're currently using. This will only match strings between 1 and 50 characters.

  • Related