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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Phone Number Validation on Dynamics CRM 365 forms

(0) ShareShare
ReportReport
Posted on by

I need to put UK mobile number validation on a field. Can someone share a working JavaScript?

*This post is locked for comments

I have the same question (0)
  • Beginner Developer Profile Picture
    55 on at
    RE: Phone Number Validation on Dynamics CRM 365 forms

    HI All,

    I have requirement to format the phone number based on country for ex : if CA and US +1 and format the phone number and if exceed 10 digit then exclude country code .

    Thanks in advance  

  • Suggested answer
    Prudvihub Profile Picture
    65 on at
    RE: Phone Number Validation on Dynamics CRM 365 forms

    Look at the following post

    prudvihub.blogspot.com/.../mobile-number-validation-in-microsoftcrm.html

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at
    RE: Phone Number Validation on Dynamics CRM 365 forms

    You could also consider using one of the following PCF controls to validate phone number or other fields.

    ScreenClip-_5B00_20_5D00_.pngScreenClip-_5B00_21_5D00_.png

    https://pcf.gallery/categories#regex

    https://pcf.gallery/check-phone-number-control/

  • Community Member Profile Picture
    on at
    RE: Phone Number Validation on Dynamics CRM 365 forms

    Hey Snitika,

    For phone number validation or more thing about this number, I use this code below:

    var phone = 'Phone number';
    var key = 'Your API key';
    var default_country = 'Country code';
    $.ajax({
        url: 'https://api.veriphone.io/v2/verify',
        method: 'POST',
        data:{phone: phone, key: key, default_country: default_country},   
        dataType: 'json',
        success: function(data) {
            console.log(data.phone_valid);   
            console.log(data.country);
            console.log(data.international_number);  
            console.log(data.carrier);         
        }
    });

    And you can get your API key in this link Veriphone

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Phone Number Validation on Dynamics CRM 365 forms

    Yes Mahendar you are correct , I did only highlighted one , it was "string"  which should be phone number.

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: Phone Number Validation on Dynamics CRM 365 forms

    Nothing wrong with the code working fine just change string to phonenumber.

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Phone Number Validation on Dynamics CRM 365 forms

    Hi Snitika,

    I have corrected your code , please try to run -

            function formatPhoneNumber() {
                var phoneNumber = Xrm.Page.getAttribute("mobilephone").getValue();
                var fixedNumber = phoneNumber.replace(/[^0-9]/g, '');
                var output = "";
                switch (fixedNumber.length) {
                    case 7:
                        output = fixedNumber.substring(0, 3) + "-" + fixedNumber.substring(4, 7);
                        break;
                    case 10:
                        output = "(" + fixedNumber.substring(0, 3) + ") " + fixedNumber.substring(4, 6) + "-" + fixedNumber.substring(7, 10);
                        break;
                    case 11:
                        if (fixedNumber.substring(0, 1) == "1")
                            output = "(" + fixedNumber.substring(1, 4) + ") " + fixedNumber.substring(5, 7) + " " + fixedNumber.substring(8, 11);
                        else
                            output = fixedNumber;
                        break;
                    default:
                        // Error No Output
                        output = phoneNumber
                        break;
    
                }
                Xrm.Page.getAttribute("mobilephone").setValue(output);
    
            }


  • Community Member Profile Picture
    on at
    RE: Phone Number Validation on Dynamics CRM 365 forms

    272874.Capture.PNGHere is my code which keeps giving me Script Error

    function formatPhoneNumber()

    {

       var phoneNumber = Xrm.Page.getAttribute("mobilephone").getValue()

       var fixedNumber = string.replace(/[^0-9]/g, '');

       var output = "";

       switch (fixedNumber.length)

       {

           case 7:

               output = fixedNumber.substring(0, 3) + "-" + fixedNumber.substring(4, 7);

               break;

           case 10:

               output = "(" + fixedNumber.substring(0, 3) + ") " + fixedNumber.substring(4, 6) + "-" + fixedNumber.substring(7, 10);

               break;

           case 11:

               if (fixedNumber.substring(0, 1) == "1")

                   output = "(" + fixedNumber.substring(1, 4) + ") " + fixedNumber.substring(5, 7) + " " + fixedNumber.substring(8, 11);

               else

                   output = fixedNumber;

               break;

           default:

               // Error No Output

               output = phoneNumber

               break;

       }

       Xrm.Page.getAttribute("mobilephone").setValue(output);

    }

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at
    RE: Phone Number Validation on Dynamics CRM 365 forms

    Take a look at the following post.

    community.dynamics.com/.../formatting-phone-number

    Maybe it will help.

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: Phone Number Validation on Dynamics CRM 365 forms

    Hi Snitika,

    Did you check existing forum posts like below:

    social.microsoft.com/.../dynamics-crm-2011-uk-phone-number-javascript-validation

    community.dynamics.com/.../119483

    These should help you.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans