Allowing a contact / phone number to have multiple forced formatting options. Follow
This script allows you to have a contact that allows for multiple types of forced formatting.
The example below shows two contact fields allowing for 4 choices: Cell, Phone, International, and Email.
Cell and Phone are formatted: (999) 999-9999
International is formatted: +1 (999) 999-9999
Email is not formatted.
<script type="text/javascript">
//Name of your Prefix/Suffix Fields
var Prefix1 = $('#udf_aem\\:Prefix1');
var Prefix2 = $('#udf_aem\\:Prefix2');
//Name of your Contact Fields
var Contact1 = $('#udf_aem\\:Contact1');
var Contact2 = $('#udf_aem\\:Contact2');
//Name of your Formatted Contact Types
var Type1 = 'Cell'
var Type2 = 'Phone'
var Type3 = 'International'
var Type4 = 'Email'
//Write out the formatting you would like to use
var Formatting1 = '(999) 999-9999'
var Formatting2 = '+1 (999) 999-9999'
//Loads the formatting on load and prefix selection
$(document).ready(Format1);
$(document).ready(Format2);
Prefix1.change(Format1);
Prefix2.change(Format2);
//First Prefix and Contact
function Format1() {
if (Prefix1.val() === Type1 || Prefix1.val() === Type2){
Contact1.mask(Formatting1);
console.log('Format1 - Formatting1');
}
else if (Prefix1.val() === Type3) {
Contact1.mask(Formatting2);
console.log('Format1 - Formatting2');
}
else {
Contact1.unmask();
console.log("UnFormat1");
}}
//Second Prefix and Contact
function Format2() {
if (Prefix2.val() === Type1 || Prefix2.val() === Type2){
Contact2.mask(Formatting1);
console.log('Format2 - Formatting1');
}
else if (Prefix2.val() === Type3) {
Contact1.mask(Formatting2);
console.log('Format2 - Formatting2');
}
else {
Contact2.unmask();
console.log("UnFormat2");
}}
</script>