Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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>

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
158 views
Welcome To Ask or Share your Answers For Others

1 Answer

I would prefer to use replace and regexp (less code, more features).

         var phone = "0123456789";
         phone.replace(/(d{3})(d{3})(d{4})/,"($1)$2-$3"); // (012)345-6789

Reference: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/replace


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...