Return to Snippet

Revision: 11188
at January 27, 2009 15:29 by xtheonex


Initial Code
<script type="text/javascript">
$(function() {
	$("input[@name='phone']").keyup(function() {
		var curchr = this.value.length;
		var curval = $(this).val();
		if (curchr == 3) {
			$("input[@name='phone']").val("(" + curval + ")" + "-");
		} else if (curchr == 9) {
			$("input[@name='phone']").val(curval + "-");
		}
	});
});
</script>

Initial URL

                                

Initial Description
This little piece of code will convert to US phone format, as typed.
Eg, As the number "0000000000" was typed, it would convert it to (000)-000-0000.

Initial Title
jQuery snippet to convert numbers into US phone number format as they're typed

Initial Tags
javascript, jquery

Initial Language
jQuery