Sureā¦
Hereās how I would do itā¦ (this is just an exampleā¦ how you implement it in your own app depends on exactly what you want to achieve with your UX).
First, Iād add a group to act as a variable (called āInput Invalid?ā) to determine whether the input is invalid.
This group would have a content type of āyes/noā
Then you need to establish whether the input is valid or not, and assign a value to that group based on that (i.e. if the input is invalid, set the value to Yes).
To do that, you need to do the folowing:
Fist set the max characters of the input to 5
Get the inputās value
Extract with regex ^[A-Za-z]\d{4}$
That will extract any texts from the input value that match your specific format, into a list of text.
So then all you have to do, is check if that list has any values or not, by using :first item is empty
If it is empty, then nothing matches and the input is invalid.
So, to do all of that, just set the datasource of your Input Invalid? group to: input's value: extract with regex: first item is empty
(using the regex above as the regex pattern).
The issue now is that the value of the Input Invalid? group will be set to yes even before the user has finished typing, so to correct that, we only want to set the value to Yes when the input value is the wrong format AND contains 5 charactersā¦ so we can add that to the expression in the Is Invalid groupās datasource.
So the full expression will now look like this:
input's value: extract with regex: first item is empty AND input's value's character count is 5
Now you just need to make something happen when the Input Invalid?'s yes/no evaluates to Yesā¦ i.e. show an error text.
So, add a text element, hidden on page load, and simply put a condition to make it visible when Group Input Invalid?'s yes/no is Yes
Thereās still one more thing to address - and that is, if we leave it at that, then the error text will only display once the user has entered 5 characters (meaning if they enter āabcā and then click away from the input element, the error message will not display).
To fix that we can add a couple more things to the condition on the text element, so that the full conditional expression to display the text will be:
Group Input Valid?'s yes/no is Yes or (input isn't focussed and ((input's value's number of characters < 5) and input's value is not empty)
note: youāll need to have enabled the experimental parenthesis feature in your app for this to work
If you want to display a similar message to confirm when the input value is valid, then Iād set a separate variable for that, using the same method outlined above, to show the same text element with different text, based on another condition.
It soundās fairly complicated, but itās not too hard to do.
Hereās a working example you can look at:
Input Validation (bubbleapps.io)