Link to home
Start Free TrialLog in
Avatar of paulvb
paulvb

asked on

formating in a form

How can I format phone numbers and zipcodes in a form?

I want to store these numbers in my database without formating
(123)456-7890 like this 1234567890.

I want the input form to have a mask, and the results form to format these numbers.

Thanks
Paulvb
Avatar of paulvb
paulvb

ASKER

???
you will need to use the replace feature when you write the results to the db.

YourVariable = Replace(Request.form("YourField, "-", "")
YourVariable = Replace(YourVariable, ")", "")
YourVariable = Replace(YourVariable, "(", "")

You'll need all three lines to replace all three characters -)(


Then you write it to your database using the variable name instead of the request.form value.


Try this, it works fine for me:

<script language="javascript">
function reformat (s)

{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}


// takes USPhone, a string of 10 digits
// and reformats as (123) 456-789

function reformatUSPhone (USPhone)
{   return (reformat (USPhone, "(", 3, ") ", 3, "-", 4))
}

// takes ZIPString, a string of 5 or 9 digits;
// if 9 digits, inserts separator hyphen

function reformatZIPCode (ZIPString)
{   if (ZIPString.length == 5) return ZIPString;
    else return (reformat (ZIPString, "", 5, "-", 4));
}

</script>


winningl
winning.....first, ee community protocol is not to lock a question with a proposed answer unless you are absolutely certain that yours is the only solution that will solve the problem.

second, you are suggesting a client side scripting solution to a server side page, which (IMHO) will put unnecessary emphasis on the client browser rather than letting the server do the work.

third, if anyone has javascript turned off this will not work therefore it is not 100% reliable for Paul

fourth, my comment was to use only 3 lines of code to do the same thing you are proposing with about 30.

Paul, if you choose to use winning's suggestion, by all means please accept the answer and award the points...you know I'm not in this for points anymore.  However, you also have the option to reject the proposed answer to ask for further clarification and/or choose another direction/comment.  This should not be taken as an insult to the proposed answer, but rather an indication that the proposed answer did not suit your requirements.
Avatar of paulvb

ASKER

Wow, what are all of those {{{ and ///
now I'm all screwed up. That's to complicated for me.

Now back to Classy's comment

I understand the replacement of the char part
it takes out the -,(, and the ), but why does the first line say (Request.form("YourField, "-", "")
and the next 2 say (YourVariable, ")", "")?

Also what is YourVariable?

YourVariable = Replace(Request.form("YourField, "-", "")
YourVariable = Replace(YourVariable, ")", "")
YourVariable = Replace(YourVariable, "(", "")

Last can I add to this as many char as I might need
for instance if a number is entered like this 123.456.7890
or will there be a problem if the code does not find this char

And thanks for the assistance
Paulvb
ASKER CERTIFIED SOLUTION
Avatar of ClassyLinks
ClassyLinks
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh, and to answer your question....no problem if it doesn't find the character....it just moves on.
Paul...is this done?
paulvb:

You have many open questions:

https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20239187
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20221988
https://www.experts-exchange.com/jsp/qShow.jsp?ta=frontpage&qid=20236526
https://www.experts-exchange.com/jsp/qShow.jsp?ta=frontpage&qid=20229648
https://www.experts-exchange.com/jsp/qShow.jsp?ta=frontpage&qid=20227449
https://www.experts-exchange.com/jsp/qShow.jsp?ta=frontpage&qid=20198946

To assist you in your cleanup, I'm providing the following guidelines:

1.  Stay active in your questions and provide feedback whenever possible. Likewise, when feedback has not been provided by the experts, commenting again makes them receive an email notification, and they may provide you with further information. Experts have no other method of searching for questions in which they have commented, except manually.

2.  Award points by hitting the Accept Comment As Answer button located above and to the left of that expert's comment.

3.  When grading, be sure to read:
https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp#3
to ensure that you understand the grading system here at EE. If you grade less than an A, you must explain why.

4.  Questions that were not helpful to you should be PAQ'd (stored in the database for their valuable content?even if not valuable to you) or deleted. To PAQ or delete a question, you must first post your intent in that question to make the experts aware. Then, if no experts object after three full days, you can post a zero-point question at community support to request deletion or PAQ. Please include the link(s) to the question(s).
CS:  https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
At that point, a moderator can refund your points and PAQ or delete the question for you. The delete button does not work.

5.  If you fail to respond to this cleanup request, I must report you to the Community Support Administrator for further action.

Our intent is to get the questions cleaned up, and not to embarrass or shame anyone. If you have any questions or need further assistance at all, feel free to ask me in this question or post a zero-point question at CS. We are very happy to help you in this task!

thanks!
amp
community support moderator