简体   繁体   中英

Thymeleaf and formatting a phone number HTML

Hi I am trying to format a phone number that is being retrieved from a database and it is coming in like this xxxxxxxxxx and I have been trying to figure out how to format it so it appears as follows xxx-xxx-xxxx. If anyone has any ideas please let me know. Thanks all

假设电话号码存储在一个名为str的变量中

return str.substring(0,3)+'-'+str.substring(3,6)+'-'+str.substring(6)

I created a wrapping TagLib/ExpressionFactory to simplify the usage of Google's libphonenumber in Thymeleaf:

<a th:href="|tel:${#phoneNumber.format('044 111 22 33', 'CH', 'E164')}|" 
th:text="${#phoneNumber.format('044 111 22 33', 'CH', 'NATIONAL')}"></a>

My Blog post Formatting phone numbers using libphonenumber in Thymeleaf explains the integration/usage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM