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

  • A problem with inserting into DB hebrew strings

    Hi, I am working with a 8.1.7 DB version, and use thin driver. I have my DB Charest configured to iso 8859P8 (which is visual Hebrew) I have no problem in making a connection and retrieving strings, using SELECT * FROM .. and then use the ResultSet.g

  • Sony monitor attached to iMac suddenly blacks out

    I have had a Sony monitor (model SDM-HS74P) attached to my iMac for over a year (and prior to that to my old iMac for several years) with no problem. Yesterday out of nowhere it blacks out. I have tried some troubleshooting things as per the Sony gui

  • No PSD thumbnails in Elements 12

    Since I upgraded from 11 I've lost the ability to see the PSD thumbnails in either Organizer or Editor. Help.

  • Imac won't boot after update

    hi guys i am new to macs I bought this for my daughter and tried to update.The update said to hold the program button and push power,well now she won't boot up just a grey sreen and what looks like a file with a blinking question mark and a face.. I

  • HT2736 How to gift a pre-ordered album on iTune?

    I pre-ordered an album I want to send as a gift to my friend but I don't have the option gift anywhere. How can I do that? If I can't I would like to cancel the pre-purchase and I need to know what to do.