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)

Javascript Regex UK Phone Number

(0) ShareShare
ReportReport
Posted on by 2,601

I'm validating a phone number on entry in CRM.  Could someone give me an example of the regex they're using if they're doing something similar.

Ideally a regex for mobile and one for landline, or otherwise a single one to cover both.

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Hosk Profile Picture
    on at

    This is what I used for a mobile phone regex with Javascript

    (070|071|072|073|074|075|076|077|078|079)\d{7,8}$

    it makes sure the the number begin with 07 and then it has 7 or 8 digits.  Apart from that, there isn't a great deal of validation you can do with phone numbers.

    I also removed brackets and replaced international codes with a zero, so they didn't cause problems with the regex expression

  • Verified answer
    CU21020959-0 Profile Picture
    2,601 on at

    I found sample Regex's for both landline and mobile numbers.  They only work if the spaces are stripped out of the numbers.  These are the 2 functions I then created:

    function Lib_IsValidMobileNumber(p) {

       p = p.replace(/\s/g,'');

       var mobileRegEx = /^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$/;

       return mobileRegEx.test(p);

    }

    function Lib_IsValidLandlineNumber(p) {

       p = p.replace(/\s/g, '');

       var landlineRegEx = /\s*\(?(0[1-6]{1}[0-9]{3}\)?[0-9]{6})\s*/;

       return landlineRegEx.test(p);

    }

  • Suggested answer
    Faisal Fiaz Profile Picture
    75 on at

    function showActivitiesReport() {
        //Get iframe
        var iframeObject = Xrm.Page.getControl("IFRAME_AllActivitiesReport");

        if (iframeObject != null) {
            var accountId = Xrm.Page.data.entity.getId();
            var strURL = "/crmreports/viewer/viewer.aspx?"
        + "action=run&context=records&helpID=Organisation%20Activities.rdl&"
    + "id=%7badcfa60f-526d-e711-810a-5065f38b06f1%7d&records=" + accountId + "&recordstype=1";


            //Set URL of iframe
            iframeObject.setSrc(strURL);
        }
    }

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