cancel
Showing results for
Did you mean:
Level: Powered On

## Checking if numbers and letters are in a text input

A simple solution I'm sure, but I can't find it anywhere. I have a text input that must contain both numbers and letters in order for the user to proceed. How do I check for this input using an If statement? I know how to do it for numbers or text only, but not both.

Thanks for the help in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User

## Re: Checking if numbers and letters are in a text input

Hi @Mark123

You can do this with a regular expression. Here's the formula you can add to a label.

`If(IsMatch(TextInput1.Text, "([A-Za-z]+[0-9]|[0-9]+[A-Za-z])[A-Za-z0-9]*"),   "Input OK",   "Input must contain letters and numbers")`
9 REPLIES 9
Highlighted
Super User

## Re: Checking if numbers and letters are in a text input

Hi @Mark123

You can do this with a regular expression. Here's the formula you can add to a label.

`If(IsMatch(TextInput1.Text, "([A-Za-z]+[0-9]|[0-9]+[A-Za-z])[A-Za-z0-9]*"),   "Input OK",   "Input must contain letters and numbers")`
Super User

## Re: Checking if numbers and letters are in a text input

Probably the easiest way would be to use the IsMatch() function and a regex expression.

Try the following for the Regex pattern

`(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)`

So you could put something like this in the Color property of the text block

`If(IsMatch(TextInput4.Text,"(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)"),Black,Red)`

If the text entry has at least one alpha and one digit then it will be black otherwise it will be red

-------------------------------------------------------------------------
If you like my response, please give it a Thumbs Up.
Level: Powered On

## Re: Checking if numbers and letters are in a text input

Thank you, just what I was looking for.

Super User

## Re: Checking if numbers and letters are in a text input

Also just to add a little, you can shorten your patterns by using the predefined patterns in PowerApps.

So, this formula would also provide the results and perhaps be a little more readable.

IsMatch(TextInput1.Text, MultipleLetters & MultipleDigits)

Happy PowerApp'ing

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Super User

## Re: Checking if numbers and letters are in a text input

@RandyHayes  I thought about that one, but won't that require more than one character and digit?

-------------------------------------------------------------------------
If you like my response, please give it a Thumbs Up.
Super User

## Re: Checking if numbers and letters are in a text input

Actually, the name is a bit deceiving - even though it is "Multiple" it is defined as "one or more"

So, "A1" would match, as would "AA11"

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Level: Powered On

## Re: Checking if numbers and letters are in a text input

@RandyHayes @Pstork1  thank you both for your help! I will try this also, will be helpful for others deciphering the code in the future. Out of curiosity, does PowerApps have a masked text input option? I have researched this but have found no possible answers. The text input I have requires 3 letters first and then 8 numbers, I was using this check as a plausible workaround.

Super User

## Re: Checking if numbers and letters are in a text input

No, there is not a masked input control currently.  So, you are limited to validating the control only.

The Match functions will be the best options for validating the contents.  But, there is nothing that would "force" or "restrict" a user to entering 3 letter and 8 numbers.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Level: Powered On

## Re: Checking if numbers and letters are in a text input

Great, thanks for letting me know. A potentially useful idea for the future maybe!

Announcements

#### Watch Sessions On Demand!

Continue your learning in our online communities.

#### PowerApps Monthly Community Call

Next Wednesday, August 21st at 8am PDT

#### Top Community Contributors for July 2019

Let's thank our top community contributors

#### Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

#### Power Platform World Tour

Coming to a city near you

#### PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

#### Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

#### Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

#### Power Summit Australia 2019

August 20-23rd 2019

Top Kudoed Authors
Users Online
Currently online: 76 members 4,736 guests
Recent signins: