格式化电话号码 [英] Formatting the phone number

查看:76
本文介绍了格式化电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的文本框在从数据库中获取电话号码后显示其值.

The below textbox is printing the value of the phone number after getting it from the database.

<table>
<tr>
<td>
<s:textfield theme="simple" name="phoneNumber"/>
</td>
</tr>
</table>

如何以(xxx)xxx-xxxx格式打印此值. 注意:这些值来自数据库,格式为0123456789 输出应该是(012)345-6789.

How to print this value in the format (xxx) xxx-xxxx. Note: The values are coming in the form of 0123456789 from the database and output should be (012)345-6789.

推荐答案

phone = "0123456789"
formated_phone = "("+phone.substring(0,3)+")"+phone.substring(3,6)+"-"+phone.substring(6,11)

这篇关于格式化电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆