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
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,387)