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 validation error

(0) ShareShare
ReportReport
Posted on by

Hi There,

I am trying below code to validate my phone number on CRM form, but it keeps giving me the attached error. I am writing my code down. its giving the result that I  want but I am getting the attached error on introducing the regular expression in my code.

function ValidatePhoneNumber() {
var mobilenumber = Xrm.Page.getAttribute("mobilephone").getValue();
if (mobilenumber != null && mobilenumber != undefined) {
var phoneno =^\d{10}$/;
if(mobilenumber.test(phoneno)){
alert("valid");}
else{
alert(mobilenumber );}
}
}

phonerror.PNG

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: phone validation error

    Hi,

    Try with this-

    =======

    function ValidatePhoneNumber() {
        var mobilenumber = Xrm.Page.getAttribute("mobilephone").getValue();
        if (mobilenumber != null && mobilenumber != undefined) {
            var phoneno = "^\d{ 10}$/";
            if (mobilenumber.test(phoneno)) {
                alert("valid");
            }
            else {
                alert(mobilenumber);
            }
        }
    }



    ==============

    Hope this helps.

  • nitinagg16 Profile Picture
    200 on at
    RE: phone validation error

    Hi,

    Please refer bobwhiteisdev.wordpress.com/.../crm-phone-number-formatting-and-validation-with-javascript

    Thanks

    Nitin

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: phone validation error

    Hi,

    Below code should work for you , I have tested  - 

            function ValidatePhoneNumber() {            
                var mobilenumber = Xrm.Page.getAttribute("mobilephone").getValue();
                if (mobilenumber != null && mobilenumber != undefined) {
                    var phoneno = /^\d{10}$/;
                    if (mobilenumber.match(phoneno)) {
                        alert("valid");
                    }
                    else {
                        alert(mobilenumber);
                    }
                }
            }


    2019_2D00_05_2D00_07_5F00_12_2D00_37_2D00_36.png

  • Community Member Profile Picture
    on at
    RE: phone validation error

    Thank you everyone

  • gdas Profile Picture
    50,091 Moderator on at
    RE: phone validation error

    Could you please close the thread by verifying above correct answer, this may helps others.

  • Community Member Profile Picture
    on at
    RE: phone validation error

    Hi,  

    I did make the regular expression as var phoneno =/^(\+?)(1?\s?)\d{10}$/;

    But now another problem I am facing is, after +1  if I enter 9 digits it accepts it as 10 digits. I don't want that to happen.  I want 10 digits irrespective of country code +1. +1(optional) 10 digits (mandatory)

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans