How can i format Telephone number from xxxxxxxxxx to (xxx)
xxx-xxxx
in telerik MVC Grid .client.template.
I tried something like this. which is not working
string formatPattern = @"(\d{3})(\d{3})(\d{4})";
columns.Bound(e=>e.ID)
.ClientTemplate(Html.Raw(String.Format("{0:###-###-####}",
"<#= Telephone #>") + "<br />" + Regex.Replace("<#= Fax
#>", formatPattern, "($1)
$2-$3")).ToString()).Title("Phone / Fax");
I tried both ways String.format and Regex.Replace
I also tried $.telerik.formatString('{0:###-###-####}'<#=
telephone =>)
but no use.
Samuel Fernandes
20-Nov-2014I got this done with the below code.
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);
}