2011-07-06 10 views

答えて

4

ライブラリを作成し、以下の2つの方法を追加してWebリソースとしてアップロードする必要があります。次に、有効にする各フィールドのChangeイベントに 'OnPhoneFieldChange'関数を割り当てます。

function OnPhoneFieldChange(context) 
{ 
    var value = context.getEventSource().getValue(); 
    if (typeof(value) != "undefined" && value != null) 
    { 
     value = formatPhoneNumber(value); 
    } 
    context.getEventSource().setValue(value); 
} 

function formatPhoneNumber(inputValue) { 
    var scrubbed = inputValue.toString().replace(/[^0-9]/g, ""); 

    var sevenDigitFormat = /^\(?([0-9]{3})[-. ]?([0-9]{4})$/; 
    var tenDigitFormat = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/; 
    var extDigitFormat = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})?([0-9]*)$/; 
    if (tenDigitFormat.test(scrubbed)) { 
     return scrubbed.replace(tenDigitFormat, "($1) $2-$3"); 
    } 
    else if (sevenDigitFormat.test(scrubbed)) { 
     return scrubbed.replace(sevenDigitFormat, "$1-$2"); 
    } 
    else if (extDigitFormat.test(scrubbed)) { 
     return scrubbed.replace(extDigitFormat, "($1) $2-$3 x$4"); 
    } 
    return inputValue; 
} 
関連する問題