How to set a mininum of characters a field can have
Question
Application Type
Reactive

I am developing an app and I need one of the input fields to have 11 characters (ex: abcdefghijk), I have already limited the maximum length to 11 characters, but I need to do a check to see if what the user put in the input field has the 11 characters required, and if not, the app will not save the column in the database and will display an error to the user. How can I do this check?


in other words, I know that Outsystems has the "maxlength" function to define how many characters are accepted in an entity attribute, but how do I define a minimum number of characters?

mvp_badge
MVP
Solution

Hi Marks,

You could add the html minlength property to the input field.

Alternatively you can add an onchange event to check the length of entered text on each change to the input and set the Isvalid property accordingly.

Regards,

Daniel

Hi, Daniël!

I tried to use the HTML minlength attribute, but I'm not getting the attribute to be passed to the app, when I publish an update the minglenght attribute is not loaded in the html code of the page, I will leave some screenshots that I made showing my service studio and the page code for you to analyze.


mvp_badge
MVP

Hi, strange for me it does show up in the HTML, but also not effective.

Alternatively, add an OnChange handler to your input:

Then add the following logic in the OnChange handler:

It worked, Thank you!

I have two more questions:

1) The message does not disappear even with the length reached, how do I make the message disappear as soon as the necessary length is reached? I tried to add another If to check if the value is equal to 10, but it seems that the OnChange Action only registers the first update made to the input. Do you have any idea how I can do this?

2) I have to do this same length check for other inputs, can I use the same TextVar used in the first input or do I have to create different variables for each one?

mvp_badge
MVP

Hi,

  1. for me the message does disappear, make sure that you set the ValidationMessage to an empty string if the input is validated correctly.
  2. Each input is normally assigned to a different variable (as the variable is where the entered data is stored).
    So yes, for each input you need a different variable. The easiest is to implement an OnChange for each input, as you have to set the InputX.IsValid and InputX.ValidationMessage properties accordingly.

See attached OML that validates two different inputs both with different min/max lengths.

Regards,

Daniel

PlaygroundReactive.oap

Hi,

I did as you show in the UML and even so the ValidationMessage does not disappear when the length reaches 10 characters. I realized that you are using the input type as text, in my project I am using an integer in the database and the input type as a number, could this be interfering with the action?


Regards,

Marks

mvp_badge
MVP

It shouldn't matter for the minlength validation using the Length() function, as that works on a string as well as on numeric data types.

However, the Maxlength property on the input does NOT work for numeric data types, so you could also add that to the logic in the validation (see attached OML).

One more notice on the Integer data type, that the max and min value of the data type limit the length of the value to max 10.

Minimum value: -2^31, which is -2147483648.
Maximum value: 2^31-1, which is 2147483647.

https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Data/Data_Types


I managed to make it work, as I was recording data in the database there was nothing in the variable when it was used in the OnChange Event, I just needed to put an assign to match the variable to the value of the attribute used.


My workflow already with the minimum and maximum length confirmation looks like this:

Thank you so much again

Graciously,

Marks

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.