cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ShaneITAutomate
Helper V
Helper V

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

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,666)