Phone number mask in a DataView WebPart (DVWP)

This came up today on the [sharepointdiscussions] list.  A user needed to display a read-only field in a phone number format; it's pretty simple, but it may be just what you need.

Assuming your list item contains a field called "Phone Number" (with a space), the following XPath will give you a number in the classic US telephone format:

<xsl:value-of select="concat('(',substring(@Phone_x0020_Number,1,3),')',substring(@Phone_x0020_Number,4,3),'-',substring(@Phone_x0020_Number,7,4))" />

If you need to mask an input, try this jQuery solution.

No Comments