Hi, I have 2 questions
Question 1.
I have an input field and I would like to check if it is 8 digits before allowing it to be written to the database.
I have tried a few methods and none works
I have a page var to capture the input and a button to perform the check
eg. my input is 12345678
So I tried on component click
insert a IF condition
INTEGER(LOG10(pageVars.HP))==7
inside the editor, I managed to get a true and false response from this but on execution, it always goes to false.
I tried to output INTEGER(LOG10(pageVars.HP)) directly using a toast but it is empty.
Question 2.
When I wanted to retrieve record from the hosted database, can I use other fields other than ID?
Please advise.
Thanks
For the first question the best solution would be to match it with a regex.
MATCHES_REGEX(pageVars.HP, "^[0-9]{8}$")
which would return true when it’s exactly 8 digits and false otherwise.
2 Likes
Hah, that’s creative use of LOG10.
The issue with the formula is that even though you bind the input field to a Number type variable, the user input is treated as a text string. So you would need to add NUMBER
around the variable:
INTEGER(LOG10(NUMBER(pageVars.HP))) == 7
should work
Sasu’s regular expression example is how a programmer would do it, but otherwise nothing wrong with your solution!
This was actually tracked already in the bug tracker: https://tracker.appgyver.com/bug-reports/p/incorrect-textinput-binding-to-number-variable
1 Like