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 / How to set field valid...
Power Apps
Unanswered

How to set field validations on Phone, Text field....

(0) ShareShare
ReportReport
Posted on by 223

Hello, 

 

Can you advise how to set field validations on Model driven apps. I've table with 2 fields Order no and desc..

Order no should only accepts numericals and if we enter characters it should display tool tip saying "Characters not allowed"

And also for description field accepts only characters without numerical values. 

 

PFA

 

@Prakash4691 

 

I have the same question (0)
  • Mira Ghaly Profile Picture
    11,413 Moderator on at

    @skolisetti 

    To apply these type of validations you need to use JavaScript with Regular Expressions.

     

  • skvsp Profile Picture
    223 on at

    Any example of reference please ?

     

  • Mira Ghaly Profile Picture
    11,413 Moderator on at

    @skolisetti 

    1. Open your form -> Switch to classic mode

    Mira_Ghaly_0-1629182121426.png

    2.Choose the field you want to run the validation upon and double click and go to the Events Tab and click Add

    Mira_Ghaly_1-1629182212518.png

    Click New

    Mira_Ghaly_2-1629182243458.png

    Give your file a name, select JS and Then Select Text Editor

    Mira_Ghaly_3-1629182304156.png

    Below is a sample javascript function to validate against regular expression

    function ValidateAgainstRegularExpression(executionContext) {
     'use strict';
     var formContext = executionContext.getFormContext();
     var fieldText = formContext.getAttribute("FieldName").getValue();
    
     if (fieldText === null) return;
    
     if (!fieldText.match("^[0-9]*$")) {
     formContext.getControl("FieldName").setNotification("Please enter only Numbers", 102);
     
     return false;
     }
     else {
     formContext.getControl(fieldName).clearNotification(102);
     return true;
     }
     
    }

     

    You need to replace the field name with the field name you are validating against and the above regular expression matches numbers.

    File now should be added to the form as below:

    Mira_Ghaly_4-1629182412826.png

     

    Click on Add Event-> Add the function name and set pass execution parameter and click ok, Then save and publish your form

    Mira_Ghaly_5-1629182467749.png

    Hope this helps!

     

     

  • skvsp Profile Picture
    223 on at

    Thank you I’ll try and update again . 

  • skvsp Profile Picture
    223 on at

    Thank you i've used input mask instead of Javascript

  • Verified answer
    EricRegnier Profile Picture
    8,720 Most Valuable Professional on at

    Hi @skolisetti, you might not need JavaScript. I assume your field type is single line of text. You can easily format to phone by with the Input Mask control. Here are the quick steps:

    1. Open your solution that contains that entity and open the main form. Click the "switch to classic" button on the top
    2. Select the phone number field and click "Change Properties"
    3. Navigate to the Controls tab and click on "Add Control"
    4. Select "Input Mask" and click add
    5. Pick you field for the Field property
    6. Enter the mask (00000000000) for the Mask property. You can also put dashes
    7. Ensure the Input Mask control is selected for Web, Phone and Tablet.
    8. Save all and publish all customization

    EricRegnier_0-1629714977964.png

     

    Hope this helps! 

  • chaffee Profile Picture
    33 on at

    The input mask is retired!

     

  • EricRegnier Profile Picture
    8,720 Most Valuable Professional on at

    Hey @chaffee, this solution dates back to 2021… not aware it is now retired but I checked the documentation and it doesn’t seem so, see https://learn.microsoft.com/power-apps/maker/model-driven-apps/additional-controls-for-dynamics-365-for-phones-and-tablets#input-mask 

    Where did you see it was retired? Cheers!

  • md7 Profile Picture
    232 on at

    Hi @Mira_Ghaly 

     

    Are you able to take a look at my error here please: https://stackoverflow.com/questions/76787526/js-script-error-cr0c5-projectid-is-not-defined

  • Mira Ghaly Profile Picture
    11,413 Moderator on at

    Hi @MD7 

    You are missing the quotation marks check below:

    Screenshot_2023-07-29-09-23-38-49_40deb401b9ffe8e1df2f1cc5ba480b12.jpg

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 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard