Is it possible to detect if a field is a text string vs numbers? (Data Validation for forms)

TL:DR Is there anyway to check if a string/field contains letters vs just numbers?

Hello everyone. I am working on an app that includes forms for contact information. These include fields like Phone Number, street number, and Zip Code which should only allow numbers, not letters. I used the number entry field which blocks users from entering letter characters on my laptop and I believe on android. But when testing the app on IOS, users can input letters. The good part is that they’re not allowed to submit the form with letters in those fields. The bad part is that it does not give them feedback or indication as to why they can not submit. So I was wondering if there was a way to check if the field contained letters and display a red rich text warning message when letters are present.

PS I tried setting the minimum value to 0 and the maximum to some arbitrary number, but it would not display an error message when text is entered


What you need is a kind of validation based on RegEx (Regular Expression).

Take a look at this RegEx challenge (or just seems that way)


1 Like

I believe you will have a problem when the ZIP starts with 0, what I would do is find an API to validate the ZIP instead, and use a text entry.

I ended up using the comment you posted on the RegEx thread of using ^ [0-9]+$ as the regular expression (although I have no idea what it actually means), and combining with custom forms using text entry fields and requiring that the regex is valid to submit. Are there any holes in that plan?

That regex will match the input from start (^) to end ($), matching one or more (+) digits [0-9]. The line must contain only digits in order to match ^ and $ on either end of the [0-9]+.

Here’s a regex translation tool whenever you need it. I think that plan is good enough.

1 Like

Thank You, I appreciate the support!

1 Like