Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Assistance with Power Apps number validation

(1) ShareShare
ReportReport
Posted on by 2
Hi all, hoping I'm in the right forum for this. One of my roles within my organisation is leading some of the solution architecture for our MS Cloud for Healthcare dynamics solution. But it is a generalised Dynamics question. 
 
I'm trying to work out the code for how to validate a number (its actually Medicare number, 10 digits with some other rules that we can ignore for the time being). There is the standard OOTB number length limiter, but no minimum length etc. I was hoping a simple expression typed into the formula bar for the MaxLength property would work (see below). Otherwise I'd just place an icon so that a tick appears next to Medicare Number if it is not less than and not greater than 10 digits. 
 
The trouble is, I can't seem to find what I need online in forums etc. that allows me to enter an expression that actually doesn't error.
 
Can anyone advise an easy code script for this?
 
 
  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 1,014 Super User 2025 Season 1 on at
    Assistance with Power Apps number validation
    Hi,

    The Medicare Number field should be created as a whole number field with a minimum value of 0 and a maximum value of 999,999,999 in Dynamics 365. You can increase the minimum value to enforce a minimum length; e.g. a minimum Value of 10,000 will ensure that the Medicare Number field contains five digits.
     
    If the Medicare Number has been created as a text field instead of a whole number field, then you have the option of building on top of this Power Fx formula to create a solution, but I really recommend creating the Medicare Number field as a whole number field.
    With({nums: Sum(ForAll(Split(txtMedicareNumber.Text, ""), 
        If(IsNumeric(Result), 1, 0)), Value),
          chars: Sum(ForAll(Split(txtMedicareNumber.Text, ""), 
          If(!IsNumeric(Result), 1, 0)), Value)},
        If(nums >= 1 && chars <=10,
           "Valid",
           "Invalid"
        ) & " Format"
    )

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,187 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,966 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans