web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Validate & Limit Numbe...
Power Apps
Answered

Validate & Limit Numbers and Characters in a Power-app Fields

(0) ShareShare
ReportReport
Posted on by 2

Hi,

 

I have two Fields in a Canvas App (which is built on a SharePoint list). One field is a Alphanumeric Field (Text) and Another is Numeric (Number).

 

I want to achieve the below.

1. The Alphanumeric Field to accept values only of 10 numbers and characters. Not less than and more than 10. 

2. The numeric field to accept only 12 numbers. Not less than or more than 12 numbers.

 

Actually i have gone through various posts but not get the exact solution. The one which i found was very complex but i need a simple validation can anyone please help?

 

Regards,

 

Categories:
I have the same question (0)
  • Verified answer
    eka24 Profile Picture
    20,923 on at

    You can use the Fill Property of the Texbox to validate based on Color.

    1. Alphanumeric

    If(Len(TextInput.Text)<10 Or Len(TextInput.Text)>10,Red,White)
    Or
    Use Notification on the Button
    If(Len(TextInput.Text)<10 Or Len(TextInput.Text)>10,Notify("The number of characters should be 10"))
     
    2. Numeric
    First of all Select the Textbox and Change the Format to number so it accepts only numbers.
    Then on the other validation:
    If(Len(TextInput.Text)<12 Or Len(TextInput.Text)>12,Red,White)
    Or Notify on a button
    If(Len(TextInput.Text)<12 Or Len(TextInput.Text)>102,Notify("The number of characters should be 12"))
    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.
  • eka24 Profile Picture
    20,923 on at

    Is the issue resolved

    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • AkshayManke Profile Picture
    2 on at

    Hi @eka24,

     

    Many Thanks for solution. It is working exactly how i am expecting.
    Just one more question. How can i restrict to submit the form if the values are not as per the requirement?

     

    I mean: If the expected characters are 12 of the specific field then the form should not be submitted if the characters are more or less.

     

    Thanks,

    Akshay 

  • Verified answer
    eka24 Profile Picture
    20,923 on at

    In that case on your submit button, use the Notity function satted above as:

    OnSelect of the button:
    If(Len(TextInput.Text)<12 Or Len(TextInput.Text)>102,Notify("The number of characters should be 12"),SubmitForm(FormName))

    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • AkshayManke Profile Picture
    2 on at

    Thanks @eka24, I will check that tomorrow and will get back to you.

     

    Regards,

  • eka24 Profile Picture
    20,923 on at

    That's fine 

    ----------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • AkshayManke Profile Picture
    2 on at

    Hi @eka24,

     

    It is working as expected. Thanks a lot for your help. Accepting as solution.

     

    Regards,

  • Chonski Profile Picture
    33 on at

    Sorry to dig such an old topic.

    I do have the same requirement but I don't know where to add the formula?

    Should I add it on the Default propery?

    Thanks a lot

  • Community Power Platform Member Profile Picture
    on at

    I did the same thing but for some reason it's giving me an error. please see the screenshot 

  • Community Power Platform Member Profile Picture
    on at

    Better is to go to the Update property of the Datacard:

     

    If(Len(TextInput.Text)>=12, 
     TextInput.Text
    )

     

    Normally, the Update property will just carry your Datacard's textbox's value. If you put a conditional on it that basically says "you can update this property if this condition is true", it will automatically throw an error condition if it sees a false value, or condition that is not met. This will cause the error message to show. In the Error Message field's "Text" property for the Datacard, you can include this custom message:

     

    If(Not(IsBlank(Parent.Error)), "Please enter a number 12 digits long.")

     

    The field must be a required field (set the property to true in the Advanced settings, as well as on the list).

     

    The only thing is, is that this message will be the same message that appears when they submit and leave it blank, too, so you can't make it overly specific - unless you put in some extra conditional logic, like:

     

    If(Not(IsBlank(Parent.Error)), If (Not(IsBlank(txtMyField.Text)), "Please enter a number 12 digits long.", "Please fill in a number."))

     

    But either will prevent submission if the condition is not met and give the red border around the field and red error message on submission like we all like when an issue meeting a validation condition occurs.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard