格式化美国电话号码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了格式化美国电话号码相关的知识,希望对你有一定的参考价值。
Generic function - Pass the context to the function for use with any field
function FormatPhoneNumber(eContext) { // Get the field that fired the event. var oField = eContext.getEventSource().getValue(); var sTmp = oField // Validate the field information. if (typeof(oField) != "undefined" && oField != null) { // Remove any non-numeric characters. var sTmp = oField.replace(/[^0-9]/g, ""); // If the number has a valid length, format the number. switch (sTmp.length) { case "4105551212".length: oField = "(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4); break; case "5551212".length: oField.DataValue = sTmp.substr(0, 3) + "-" + sTmp.substr(3, 4); break; } } }
以上是关于格式化美国电话号码的主要内容,如果未能解决你的问题,请参考以下文章