Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Validate Text Input has more than 8 numbers

Like (1) ShareShare
ReportReport
Posted on 29 Jan 2025 23:15:25 by 41
Hello, 

I am using the modern text input field in a canvas app which I have added to a container. I want to be able to validate that the text input field has 8 characters or more. The text input cannot be blank and has to have 8 or more characters. I have the following code, but I get an error. 
If(
    And( Len(Self.Value)>= 8 , IsBlank(Self.Value),
    "Error",
    "None"
)

What is the best way for the validation state to check that it is not blank and has 8 or more characters in it? 
Categories:
  • timl Profile Picture
    timl 34,403 on 30 Jan 2025 at 11:09:21
    Validate Text Input has more than 8 numbers
     
    Apologies, yes you're absolutely correct. I misread the question as the input text being no more than 8 characters.
     
    @ElvirBotic - perhaps you can mark @tsa-svd2srv post as the answer if it solves your problem.
  • tsa-svd2srv Profile Picture
    tsa-svd2srv 197 on 30 Jan 2025 at 10:04:14
    Validate Text Input has more than 8 numbers
    timl:
     
    If we look at your code (my code revised) with just the idea that it need to be 8 or more characters:
    If(
        Len(Self.Value)> 8,
        "Error",
        "None"
    )
    Your code results in "Error" if Len is greater than 8.
     
    This is backwards to the requesters post.
     
    The code I submitted is correct.
  • timl Profile Picture
    timl 34,403 on 30 Jan 2025 at 09:51:49
    Validate Text Input has more than 8 numbers
    Just to extend on @PStork1's Regex post below, you would need to add "^$" to also check for blank values, and specify {9,} if you don't want it to trigger for input that's exactly 8 characters long.
     
    If(
        IsMatch(Self.Value, "^$|^.{9,}$"),
        "Error",
        "None"
    )
    
     
  • Verified answer
    timl Profile Picture
    timl 34,403 on 30 Jan 2025 at 09:44:48
    Validate Text Input has more than 8 numbers
     
    If you're curious as to why your formula caused an error, it was because you were missing a closing bracket after the And function.
     
    Irrespective of that, you would need to call the Or function to test that the value is greater than 8 characters OR "is blank". Note that the earlier post specified "< 8" which is incorrect. 
    If(
        Or(Len(Self.Value)> 8 , IsBlank(Self.Value)),
        "Error",
        "None"
    )
    
     
  • Suggested answer
    Pstork1 Profile Picture
    Pstork1 64,996 on 30 Jan 2025 at 02:47:05
    Validate Text Input has more than 8 numbers
    I would use a REGEX expression for this and an IsMatch() function.  This should work

    isMatch(self.Text, "^\d{8}$")

    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

    Paul Papanek Stork, MVP
    Blog: https://www.dontpapanic.com/blog
    ​​​​​​
  • Suggested answer
    tsa-svd2srv Profile Picture
    tsa-svd2srv 197 on 30 Jan 2025 at 00:22:42
    Validate Text Input has more than 8 numbers
    If(
        Or(
            IsBlank(Self.Value),
            Len(Self.Value) < 8
        ),
        "Error",
        "None"
    )
    This should do it. Have fun!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,666

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,996

Leaderboard
Loading started