Restrict a field to a fixed character length

  • 0
  • 1
  • Question
  • Updated 5 years ago
  • Answered

There is a "text" field, is there a way to restrict the users to enter only 11 characters.

Entered characters should not exceed 11 or it should not be less than 11 characters.

Photo of Dilip

Dilip

  • 0 Points

Posted 5 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,434 Points 20k badge 2x thumb
Using the image onload technique it is a snap to do! See code in the pastie below and the attached screenshot:

Pastie Database

https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=298
Photo of Dilip

Dilip

  • 0 Points
Thanks for the response.
It will be helpful if you can let me know the steps to do the Image on load technique. Also where should the code be used?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,434 Points 20k badge 2x thumb
There is a native function for this inn QuickBase. Just edit the field properties for the field and set the "Max Characters" to 11.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,434 Points 20k badge 2x thumb
I was anticipating you would add that answer. However on re-reading the question the OP also wanted to insure that "no less than 11 characters" were entered. While I don't have a solution to that yet (but it won't talk long once more details are forthcoming) the point I would like to make is that the problem with the current architecture is that if QB does not have a specific feature implemented you are often at a dead end unless you use the image onload technnique. The problem with hardcoding product features is that over time a user's requirements evolve and expand and it does not take much to make change to quickly make a native solution inapplicable.

Now on the issue of requiring at least 11 characters there are a lot of options depending on additional requirements. You could pad the input to make it exactly 11 characters; you could throw up a dialog message if the input was short; or you could prevent the form from saving until 11 characters were entered. All of these scenarios can be solved using the image onload technique. While I understand that QuickBase and users would like to use checkbox configurable functionality, you will never be able to meet all user requirements unless you have an escape hatch of using script when needed. The product really has to evolve to be more flexible and accommodating of new requirements without waiting for QuickBase to evaluate, prioritize, design and implement specific hardcoded feature sets.

In the meantime using the image onload technique will solve all  your problems.
Yes, I see now that Dilip wanted to enforce exactly 11 characters.  

In native QuickBase I would put up a field by formula which measures the length of the input field and warns the user if its less that 11 characters.  But its messy to actually enforce a form rule to block the save as I have found that those "Abort the save" type rules to not always see the users latest input and may block the save when the user has edited the field to correct their input but not tabbed out of the field yet.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,434 Points 20k badge 2x thumb
Using iol you can add a pattern attribute to the <input> so that it requires exactly 11 characters.

<input ... id="_fid_7" ... pattern=".{11}" required="required">


Then when the field blurs you test this.validity.patternMismatch and throw up a message if the pattern does not match.

Pastie Database

https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=299