hello1215
08-26-2002, 04:52 PM
How can I reformat phone numbers to contain dashes,
ex: 123-456-7890. I want the dashes to be added once the user leaves the field.
ex: 123-456-7890. I want the dashes to be added once the user leaves the field.
|
||||
reformatting phone nubmerhello1215 08-26-2002, 04:52 PM How can I reformat phone numbers to contain dashes, ex: 123-456-7890. I want the dashes to be added once the user leaves the field. usban 08-26-2002, 05:06 PM I imagine tha all the phone numbers in your country have the same length. If so you can do this: imagine you have number here: form1.phone.value number = form1.phone.value; new = number.subtring(0,3)+"-"+number.subtring(4,6)+"-"+number.subtring(7,9); I think that's it. You have cut the phone number in three parts with dashes inside. usban 08-26-2002, 05:07 PM What a mess!!! I've forgotten the "s" of substring. Try with this one. new = number.substring(0,3)+"-"+number.substring(4,6)+"-"+number.substring(7,9); hello1215 08-26-2002, 05:36 PM So far, this is what I have <script language="JavaScript"> function number(field) { return (reformat(field , "",3, "-",3, "-",4)) } </script> <form name="form" > <tr> <td>Phone:</td> <td><input type="text" name="phone" value="" maxlength=12 onChange="number(this)"></td> </form> What do I need to do to get this to work? Adding dashes once the user leaves the field. jkd 08-26-2002, 07:59 PM function formatPhone(phone) { return phone.toString().replace(/\D/g,'').replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3'); } something like that should work. |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum