Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

TFN Validation in Contact Form

Posted on by 49
Hi All,

Is there a way to validate the TFN number entered by user on a form(e.g - Contact Form). Like proper validation.
I am new to Dynamics 365 Customer insights, Just working on Trail version.

What I tried:
1. Created a solution in power apps .
2. Included the Contact table.
3. Navigated to Contact forms and included TFN as new form field.
4. Save and publish , the new field appeared on my trial version.

Now I wish to add validation check, Like do we add  any business rule, or an api  or javascript to validate it?

Thank in advance
  • Verified answer
    Sohom Ghorai Profile Picture
    Sohom Ghorai 43 on at
    TFN Validation in Contact Form
    You can use JS webresource that will trigger onchange of the field or onsave 
    For more details refer : https://learn.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/web-resources
  • Suggested answer
    Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    TFN Validation in Contact Form
    Hi partner,
    Maybe you can try to use PCF control if you don't want to use Javascript code.
    There are some existing controls, you can select one as your needs.

    I hope you can mark my answer verified if it answer your question! If you have any questions, please feel free to contact me.
    Regards,
    Leah
  • Suggested answer
    Pradeep Rai Profile Picture
    Pradeep Rai 5,490 Super User 2024 Season 2 on at
    TFN Validation in Contact Form
    You can write JavaScript which will trigger on change of TFN Number field as shown in below script code:
     
    function onChangeTFN(executionContext) {
        var formContext = executionContext.getFormContext();
        var tfnField = formContext.getAttribute("<yourtfnnumberlogicalname>"); 
        
        if (tfnField) {
            var tfnValue = tfnField.getValue();
            if (!validateTFN(tfnValue)) {
              formContext.getControl("<yourtfnnumberlogicalname>").setNotification("Invalid TFN number", "Error");
            }
        }
    }
    
    
    function validateTFN(tfn) {
    
        var tfnRegex = /^\d{3} ?\d{3} ?\d{3}$/;
    
    
        tfn = tfn.replace(/\s/g, '');
    
    
        return tfnRegex.test(tfn);
    }
    
     
    You can use below link to know more about adding on change event :

    https://carldesouza.com/adding-an-onchange-script-programmatically-in-dynamics-365-power-apps/
     
    Thank You,
    Pradeep Rai.
     
    Please mark ,my response as VERIFIED. if it helps you to resolve the query.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans