have you tried a more basic approach yet? like the following:
only allow numeric input on this textbox and limit by 10 numbers in form validation:
HTML Code:
<form id="form1" name="form1" method="post" action="handler.php">
<input id="phone" name="phone" type="text" value="" />
</form>
do the form validation and keystroke limiting something like follows in the external .
js file:
Code:
document.form1.onsubmit = function () {
if (this.value.length == 10) { // force length of 10.
return true;
} else {
alert("You need a 10 digit phone number including area code!");
return false;
}
}
document.formj1.phone.onkeypress = function () {
if (!e) var e = window.event;
if ([e.keyCode||e.which]==8||[e.keyCode||e.which]==46) // this is to allow backspace or delete.
return true;
if ([e.keyCode||e.which] < 48 || [e.keyCode||e.which] > 57)
e.preventDefault? e.preventDefault() : e.returnValue = false;
}
handler.php function and usage:
PHP Code:
function format_phone($phone) {
$phone = ((strlen($phone)==7)?"012":"").$phone; // insert default area code if omitted.
$phone = "(".substr($phone_1, 0, 3).") ".substr($phone,3,3)."-".substr($phone,6,4);
return $phone;
}
$phone = format_phone($_POST("phone"));
__________________
Sincerely,
Pierre "Greywacke" du Toit
[email protected]
don't worry about my 0 thankyou's either way, i would say thank you should you help, and i will gladly help others when this work rush is over.