Save a phone number without the input mask

Hi,
I actually have 2 related issues that I hope you might be able to help me with.
I have a form linked to an interactive report, so when I click a record, the form is populated with the record's data. I just started using the new text field masked input plugin to handle phone number formatting, etc., which Patrick recommended.
The plugin works nicely when a phone number being displayed from the source is 10 characters. The input mask I'm using is (999) 999-9999. However, I also have phone numbers in records that don't include the area code. When I select one of those records, the phone number field is blank. I would like it to display 999-9999, and be right justified. Is there an easy fix for that?
My next problem occurs when I try to save the record. The process tries to save the phone number, including the mask, (14 characters), to the table. I only want to save the number to the table, excluding the mask. I'm sure there is a way to do this but I haven't found it yet.
Thanks in advance for any help,
Gary

This is my solution to parsing the number only from the masked phone number:
1) Create a field, 'P1_PHONE_MASKED', with a phone number mask: (?***) 999-9999
2) Create a hidden Database Column like: 'P1_PHONE' It will initially hold the value of the record's phone column.
3) create a javascript function in the page's before header section, between the space tags, to strip out all non-numeric values and update the hidden field:
function remmask(src,tar){
var mystring = $x(src).value;
mystring = mystring.replace(/\D/g,'');
$x(tar).value = mystring;
4) Place the function call in the from in the HTML Form Elements Attributes of P1_PHONE_MASKED: onBlur="javascript:remmask('P1_PHONE_MASKED','P1_PHONE');"
Now, anytime you change the value in P1_PHONE_MASKED, P1_PHONE gets updated with just the number values from P1_PHONE_MASKED.
You can also add validation to the function to ensure that the length of the phone number is either 7, no area code, or 10, including area code. Normally, the mask should handle validation, but as you can see, to make this work, I had to make the mask more flexible, to allow for alpha numeric values in the first 3 positions and to allow for either 7 or 10 characters. Unfortunately, that means a user could enter something like XXX12 and the mask won't reject it.
Partial solution to displaying ( ) 999-9999 in the masked input field P1_PHONE_MASKED when initially selecting a record for display.
1) Make the Source Type for P1_PHONE_MASKED "SQL Query"
2) Insert a query similar to the one below into "Source Value or Expression"
SELECT
CASE
WHEN length(METAREPO.CONTACTS.CONTACT_PHONE) = 10
THEN
METAREPO.CONTACTS.CONTACT_PHONE
WHEN length(METAREPO.CONTACTS.CONTACT_PHONE) = 7
THEN
'___'||METAREPO.CONTACTS_2011.CONTACT_PHONE
END
FROM METAREPO.CONTACTS
WHERE METAREPO.CONTACTS.CONTACT_ID = :P1_CONTACT_ID
This will display 7 digit phone nubers as follows: (___) 999-9999 in the masked field: P1_PHONE_MASKED.
I wanted to use spaces between the () to make it perfect, but I'm unable to get this to work. I've tried things like:
' '||METAREPO.CONTACTS_2011.CONTACT_PHONE
LPAD(METAREPO.CONTACTS_2011.CONTACT_PHONE,3,' ')
Both of which work in PL/SQL Developer, but not in Apex. I believe this is because HTML collapses spaces by default.
I would like very much to resolve this last issue. Any suggestions?
Regards,
Gary

Similar Messages

Maybe you are looking for

  • HT2490 the "X" to close tabs on my macbook is gone how do I get it back to work again

    the "X" to close tabs on my macbook is gone how do I get it back to work again

  • New update has messed up my playlists

    I installed the new 10 OS software this morning which seemed fairly smooth.  However, my music and playlists are all scrambled.  Is there a simple way to reinstate them to the way they were please? Cheers

  • Trouble getting photos from iphoto to iPhone

    A few months back I had updated my iphone to 4.3.2 (somewhere around there) and it began transferring only a very small subset of the photos from photo to my phone.  After the sync, it would say something to the effect of "Image "DSC_00112" could not

  • Add a table row

    I have a standard html table in and ICE div and want my client to be able to add table rows to enter new problems reported. When in edit mode we can edit content in the existing rows, but do not seem to be able to add a new row. Suggestions? Morris

  • Bluetooth stop working

    I just bought my iphone last year. And i couldn't use my bluetooth in my phone. I turn it on and my bluetooth headphone but it can't found my headphone. I really sad. And what should i do now? Need HEPL!! Thanks