Blog - Single Post

How to Format Telephone Numbers in Telerik MVC Grid

  • Friday, January 6, 2012
  • by hbopuri

In Telerik Grid bound the column like this

 .ClientTemplate("<#= GetPhoneFaxTemplate(data) #>").Title("Phone / Fax"); 

And the Scripts goes like this

function GetPhoneFaxTemplate(data) {
        if (isNumeric(data.Telephone)) {
            var phone = $.telerik.formatString('{0:(###) ###-####}', Number(data.Telephone))
        }
        else {
            phone = data.Telephone;
        }
        if (isNumeric(data.Fax)) {
            var fax = $.telerik.formatString('{0:(###) ###-####}', Number(data.Fax))
        }
        else {
            fax = data.Fax;
        }
        template = phone + "<br />" + fax;
        return template;
    }
    function isNumeric(n) {
        return !isNaN(parseFloat(n)) && isFinite(n);
    }