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

Notifications

Announcements

No record found.

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

    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

    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

    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

    Thank you everyone

  • gdas Profile Picture
    50,091 Moderator on at

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

  • Community Member Profile Picture
    on at

    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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans