SOLVED

Limiting the number of characters in a field on a form?

Go to solution
Anonymous
Not applicable

Limiting the number of characters in a field on a form?

Hi Marketo folks!

I want to limit the characters that are allowable on the first name and last name fields on a form. Some of our backend systems were set up a long time ago with a maximum of 20 characters for the name fields.

I ran across this post that the great Sanford Whiteman​ responded to:

Set minimum length for a text field on form?

That has me exploring using input masking to do this. There are a few issues that I am running in to:

1. I don't like the underscores that appear to show the slots. People are very seldomly going to have more than 20 characters in their names so no need to advertise that the limitation is there.

2. It doesn't allow spaces. Some people, especially people with Latin names, have multiple names that they want to put in fields so they separate those with spaces. Maybe there is a way to add spaces to a mask definition? I don't know how to do that though.

Any help with these?

Thanks,

Delwin

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Limiting the number of characters in a field on a form?

MktoForms2.whenReady(function(form) {

   MktoForms2.$("body").on("mkto_inputmask_polyfilled", function(e) {

      MktoForms2.$.mask.definitions["_"] = "[A-Za-z0-9 ]";

      ["FirstName","LastName"].forEach(function(fieldName){

         var field$ = form.getFormElem().find("[name='" + fieldName + "']")

        

         field$.mask("____________________", { placeholder: "" });

      });

   });

});

(I really hate having to use the jQuery (instead of native DOM) event and functions in there, but I have no choice with the input mask plugin.)

View solution in original post

2 REPLIES 2
SanfordWhiteman
Level 10 - Community Moderator

Re: Limiting the number of characters in a field on a form?

MktoForms2.whenReady(function(form) {

   MktoForms2.$("body").on("mkto_inputmask_polyfilled", function(e) {

      MktoForms2.$.mask.definitions["_"] = "[A-Za-z0-9 ]";

      ["FirstName","LastName"].forEach(function(fieldName){

         var field$ = form.getFormElem().find("[name='" + fieldName + "']")

        

         field$.mask("____________________", { placeholder: "" });

      });

   });

});

(I really hate having to use the jQuery (instead of native DOM) event and functions in there, but I have no choice with the input mask plugin.)

View solution in original post

Anonymous
Not applicable

Re: Limiting the number of characters in a field on a form?

Perfect! Just for other folks who might bump into this into the future.

- Still turn on Mask Input on the form

- Add the code that Sanford has provided in to an HTML element on the landing page wrapped in script tags.

Thanks Sanford Whiteman​!