cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ezjensen
Advocate II
Advocate II

Minimum Character length and Must include a number

Hi All--

 

I have a textbox that needs some validation.  I have two requirements, and a label control that will display different text based on the textbox entry.

 

Requirements:

  • Must be 4 at least 4 characters in length
  • Must include a number

Label text property:

  • If(Len(txtCoworkerID.Text) >= 4, "Valid Format", "Invalid Format") - Working

How can I add a check for a number in the textbox?  I've tried a few things and cannot seem to get it working.

 

ezjensen_0-1621277452316.png

 

ezjensen_1-1621277467129.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@ezjensen 

Change to:

With({nums: Sum(ForAll(Split(txtCoworkerID.Text, ""), If(IsNumeric(Result), 1, 0)), Value),
      chars: Sum(ForAll(Split(txtCoworkerID.Text, ""), If(!IsNumeric(Result), 1, 0)), Value)}
    If(Len(txtCoworkerID.Text)=4 &&
       nums >= 1 && chars <=3,
       "Valid",
       "Invalid"
    ) & " Format"
)
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

9 REPLIES 9
RandyHayes
Super User
Super User

@ezjensen 

If you have a standard pattern it is much easier by using a regular expression.  So, something like - needs to be 3 numbers and one letter or one letter and 3 numbers - would be simple to match.

 

This formula will get you closer to the results you are trying to achieve:

If(
    Sum(ForAll(Split(txtCoworkerID.Text, ""), If(IsNumeric(Result), 1, 0)), Value)=3 &&
    Len(txtCoworkerID.Text)=4,
    "Valid",
    "Invalid"
) & " Format"

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
ezjensen
Advocate II
Advocate II

Thank you @RandyHayes   Unfortunately, it can be a mix, with 1-4 numbers and 0-3 letters

 

ex. 1234, 1abc, 12ab, 123a

RandyHayes
Super User
Super User

@ezjensen 

Change to:

With({nums: Sum(ForAll(Split(txtCoworkerID.Text, ""), If(IsNumeric(Result), 1, 0)), Value),
      chars: Sum(ForAll(Split(txtCoworkerID.Text, ""), If(!IsNumeric(Result), 1, 0)), Value)}
    If(Len(txtCoworkerID.Text)=4 &&
       nums >= 1 && chars <=3,
       "Valid",
       "Invalid"
    ) & " Format"
)
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

@RandyHayes 

Invalid number of arguments. Received 3, expected 2.

ezjensen_1-1621284823300.png

 

RandyHayes
Super User
Super User

@ezjensen 

Please scrub through the formulas I provide as I type them by hand without the aid of a design editor.

Comma was missing...

With({nums: Sum(ForAll(Split(txtCoworkerID.Text, ""), If(IsNumeric(Result), 1, 0)), Value),
      chars: Sum(ForAll(Split(txtCoworkerID.Text, ""), If(!IsNumeric(Result), 1, 0)), Value)},
    If(Len(txtCoworkerID.Text)=4 &&
       nums >= 1 && chars <=3,
       "Valid",
       "Invalid"
    ) & " Format"
)

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
ezjensen
Advocate II
Advocate II

@RandyHayes 

 

Got it.  there was a comma missing....

ezjensen_2-1621285120841.png

 

ezjensen
Advocate II
Advocate II

With({nums: Sum(ForAll(Split(txtCoworkerID.Text, ""), 
    If(IsNumeric(Result), 1, 0)), Value),
      chars: Sum(ForAll(Split(txtCoworkerID.Text, ""), 
      If(!IsNumeric(Result), 1, 0)), Value)},
    If(Len(txtCoworkerID.Text)=4 &&
       nums >= 1 && chars <=3,
       "Valid",
       "Invalid"
    ) & " Format"
)
ezjensen
Advocate II
Advocate II

thank you for your help @RandyHayes 

RandyHayes
Super User
Super User

@ezjensen 

No problem.  The comma is free 😁

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

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