Click to See Complete Forum and Search --> : Format Phone Number script
jshelley
05-10-2003, 11:56 PM
I have recently used the "Format Phone Number" script available on this site at http://javascript.internet.com/forms/format-phone-number.html
I am looking for a quick and painless way of formatting multiple Phone Number fields on the same page. I'm hoping that somehow I could pass the field name to the script.
This is probably simple, but I'm a bit new to JavaScript.
Thanks.
Charles
05-11-2003, 06:28 AM
I've taken the liberty of giving you a script that will convert from any format.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<form action="">
<script type="text/javascript">
<!--
function PhoneNumber (s) {this.number = s.match(/\d/g)}
PhoneNumber.prototype.toString = function () {return ['(', this.number[0], this.number[1], this.number[2], ')', this.number[3], this.number[4], this.number[5], '-', this.number[6], this.number[7], this.number[8], this.number[9]].join('')}
// -->
</script>
<div>
<input type="text" onchange="this.value = new PhoneNumber(this.value)">
<input type="submit">
</div>
</form>
jalarie
05-12-2003, 09:38 AM
I have a JavaScript routine, available for free, which will take in just about any format you can think of and give back whatever you wish. Write to me directly at jalarie@umich.edu and ask for phonfmt1.js if you're interested.