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 III
Super User III

@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

View solution in original post

9 REPLIES 9
RandyHayes
Super User III
Super User III

@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
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 III
Super User III

@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

View solution in original post

@RandyHayes 

Invalid number of arguments. Received 3, expected 2.

ezjensen_1-1621284823300.png

 

RandyHayes
Super User III
Super User III

@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
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 III
Super User III

@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

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

Top Solution Authors
Top Kudoed Authors
Users online (21,002)