cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
er
Advocate IV
Advocate IV

Validate phone number/email

I could not find exactly what I was looking for in previous posts, so I decided to create a new one.

 

Is there a way to make sure the text field for users to input their email contains the "@" sign? Or that the phone number field has at least ten characters?

 

Any help would be much appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
CarlosFigueira
Power Apps
Power Apps

You can use the IsMatch function, which should do what you need. For example, if you want to highlight a text input that should contain an e-mail, you can use the following expression in its BorderColor property.

If(IsMatch(TextInput1.Text, Match.Email), Color.Blue, Color.Red)

The function IsMatch can be used for a lot of scenarios, but for simpler cases, like in your second example (minimum length), you can use the Len function, which returns the number of characters in a string. In an example similar to the one above, you could set the border color of the text input that is used to enter the telephone number to the expression below:

If(Len(TextInput2.Text) < 10, Color.Red, Color.Blue)

 

View solution in original post

7 REPLIES 7
CarlosFigueira
Power Apps
Power Apps

You can use the IsMatch function, which should do what you need. For example, if you want to highlight a text input that should contain an e-mail, you can use the following expression in its BorderColor property.

If(IsMatch(TextInput1.Text, Match.Email), Color.Blue, Color.Red)

The function IsMatch can be used for a lot of scenarios, but for simpler cases, like in your second example (minimum length), you can use the Len function, which returns the number of characters in a string. In an example similar to the one above, you could set the border color of the text input that is used to enter the telephone number to the expression below:

If(Len(TextInput2.Text) < 10, Color.Red, Color.Blue)

 

View solution in original post

That worked perfectly, thank you! 

 

Is there a way that I can add this to the "OnChange" so that it doesn't come up red until they insert something incorrectly?

Hello,

 

I tried it on my form and it doesn't work

 

If(IsMatch(DataCardValue12.Text;Match.Email);Color.Blue;Color.Red)

 

Can you help me ?

 

Helene

 

Anonymous
Not applicable

This answer is working well. but could not stop form to get submit and update data back to data source. My email input box isinside datacard? any help would be highly apprecieted.

@Anonymous

 

To validate your data on form submission, change the formula for your submit button from SubmitForm(EditForm1) to:

 

If(IsMatch(TextInput1.Text, Match.Email), SubmitForm(EditForm1))

 

 

If(Len(TextInput2.Text) < 10, Color.Red, Color.Blue)

 This formula can't be used for phone number as it checks the length of the string doesn't matter if its a number or a letter.

 

If they type "TELEVISION" in the phone number textbox it will still validated it right?

You might be able to use a combination of the len and IsNumeric functions to make sure it's a number and that it's at least 10 numbers long. I haven't tested it though so can't say for sure 🙂

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (44,369)