locked
Formatting in phone number fields RRS feed

  • Question

  • Hello,

    I'm wondering if you can help me. I need to set up some field formatting so that when I enter a phone number it automatically inserts a space. For example 0000 000 0000

    I understand JavaScript will need to be used, but could someone please tell me how to do this? 

    Thanks in advance.

    Monday, February 17, 2014 11:21 AM

All replies

  • Hi Chris,

    Refer this.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in

    Monday, February 17, 2014 11:46 AM
  • Monday, February 17, 2014 12:12 PM
  • Hi Chris,

    Refer this.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in

    Perhaps you can help. The field name im using is called "new_mobilephonenumber", which I've changed and I still get an error. Can someone take a look at what I'm doing wrong?

    // Mobile phone number format

    function FormatPhoneNumber()
    {
        ret = true;
        var phone1 = Xrm.Page.getAttribute("new_mobilephonenumber").getValue();
        var phone2 = phone1;

        if (phone1 == null)
            return true;

        // First trim the phone number
        var stripPhone = phone1.replace(/[^0-9]/g, '');

        if (stripPhone.length < 10) {
            alert("new_mobilephonenumber" + phoneDesc + " you entered must be at 10 digits. Please correct the entry.");
            Xrm.Page.ui.controls.get("new_mobilephonenumber").setFocus();
            ret = false;
        } else {
            if (stripPhone.length == 10) {
                phone2 = "(" + stripPhone.substring(0, 3) + ") " + stripPhone.substring(3, 6) + "-" + stripPhone.substring(6, 10);
            } else {
                phone2 = stripPhone;
            }

        }


        Xrm.Page.getAttribute("new_mobilephonenumber").setValue(phone2);
        return ret;
    }


    Monday, February 17, 2014 12:16 PM
  • Monday, February 17, 2014 12:20 PM
    Moderator
  • Can anyone take a look at the code itself please?
    Tuesday, February 18, 2014 10:25 AM