cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ShaneITAutomate
Post Patron
Post Patron

Max length and only allow a certain text format

Hi,

 

Is it possible to only allow certain values in a text input field?

 

I have a few text inputs i want the users to only allow them to enter AB000001 to AB999999

 

I have set the max input to 8 and i have a auto sequencing feature in the defaults that i need its code is

If(IsEmpty(Gallery_1.AllItems),"", NextSampleID.Text)

 

Which also has to be in the default list

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-albai-msft
Community Support
Community Support

Hi @ShaneITAutomate ,

The key is that the users need to enter the values in the required format. We can only prompt and clear incorrectly formatted input.

I do a test in my side, you can refer to my solution.

1. Set OnChange property of your TextInput to(leave Default property blank):

 

If(Value(Right(TextInput.Text,6))>000001&&Value(Right(TextInput.Text,6))<999999&&IsMatch(Left(TextInput.Text,2),"AB"),true,Notify("your text is wrong, please re-enter",NotificationType.Error);Reset(TextInput))

 

You can also use this Formula(this has same results as above):

If(IsMatch(TextInput.Text,"AB\d{6}$"),true,Notify("your text is wrong, please re-enter",NotificationType.Error);Reset(TextInput))

2. Add a label under this TextInput, set Text property to:

 

“Format of entered value should like AB000001.”

 

Then set its Visible property to:

 

If(!IsBlank(TextInput.Text),true,false)

 

After above steps, the alert label will display when Textinput is not blank. Also, if user enter wrong format or length is less than eight, error message will prompt and at the same time, the TextInput will be reset. 

Best Regards,

Allen

View solution in original post

1 REPLY 1
v-albai-msft
Community Support
Community Support

Hi @ShaneITAutomate ,

The key is that the users need to enter the values in the required format. We can only prompt and clear incorrectly formatted input.

I do a test in my side, you can refer to my solution.

1. Set OnChange property of your TextInput to(leave Default property blank):

 

If(Value(Right(TextInput.Text,6))>000001&&Value(Right(TextInput.Text,6))<999999&&IsMatch(Left(TextInput.Text,2),"AB"),true,Notify("your text is wrong, please re-enter",NotificationType.Error);Reset(TextInput))

 

You can also use this Formula(this has same results as above):

If(IsMatch(TextInput.Text,"AB\d{6}$"),true,Notify("your text is wrong, please re-enter",NotificationType.Error);Reset(TextInput))

2. Add a label under this TextInput, set Text property to:

 

“Format of entered value should like AB000001.”

 

Then set its Visible property to:

 

If(!IsBlank(TextInput.Text),true,false)

 

After above steps, the alert label will display when Textinput is not blank. Also, if user enter wrong format or length is less than eight, error message will prompt and at the same time, the TextInput will be reset. 

Best Regards,

Allen

Helpful resources

Announcements
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Government Carousel

New forum: GCC, GCCH, DoD - Federal App Makers (FAM)

In response to the unique and evolving requirements of the United States public sector, Microsoft has created Power Apps US Government.

Users online (2,402)