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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Validate phone number JS

(0) ShareShare
ReportReport
Posted on by

Hello expert ,

I need to validate a phone number that contain up to 10 digits without spaces & should not start  with 04 or 05.

this is my function:

function ValidatePhoneNumber() {
debugger;
var mobilenumber = Xrm.Page.getAttribute("telephone1").getValue();
if (mobilenumber != null && mobilenumber != undefined) {
var pattern = /^[0-9]\d{2,4}\d{6,8}$/;
if (mobilenumber.match(pattern)) {
return true;
}
else {

alert("Please Enter Valid Mobile NUmber");
Xrm.Page.getAttribute("telephone1").setValue(null);
}

}

}

Thank you in advance

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Hi David Thorn,

    I am guessing that your question is that it is not working. The problem seems to be because of the regular expression.

    Can you please try this pattern?

    ^(?!(04|05))(?=\d{10}$)\d+/

    This is the pattern for checking if the first two digits are not 04 or 05, not containing any spaces and is exactly 10 digits long. You can easily verify the regex by running it in Chrome Developer Tools. A demo is available at https://regex101.com/r/E9NFF2/1/

    - Sara

  • Community Member Profile Picture
    on at

    Hello Sara ,

    Thank you for your answer.

    But i got an error when i sue this pattern , my function is not defined at eval time ,when i get back to my script its wworking fine but the validation not.

    Thank you

  • Community Member Profile Picture
    on at

    I just find why ,a bracket is missing  /^(?!(04|05))(?=\d{10}$)\d+/

    Thank you so much for your help & for the link!

  • Community Member Profile Picture
    on at

    and if i want a validation of a number that starts with : 04 or 05

    i tried /^(?:04|05)(?=\d{10}$)\d+/  but its not working

  • Community Member Profile Picture
    on at

    I just find It!thanks

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans