...

View Full Version : Creating a JS control for my form



chornbeck
08-02-2006, 03:08 PM
I need to control the form entry of people's phone numbers on my forms. Some people aren't entering one, some are entering too many or not enough numbers, etc.

What I'd like to do is set it where the JS checks to see that 10 numbers have been entered, regardless of any additional characters (like -, (, ), space, etc..). If more or less than 10 numbers are entered, I would like it to display a message in a certain position below the form stating "Please enter your phone number in the proper format (xxx-xxx-xxxx)"

Any help on how to get started doing this?

Thanks!

vwphillips
08-02-2006, 03:15 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--

function CkNumbers(obj,nu){
var val=obj.value.replace(/\D/g,'');
if (val.length!=nu){
alert(nu+' Digits Required');
}
}
//-->
</script></head>

<body>
<input onblur="CkNumbers(this,10);" >
</body>

</html>

chornbeck
08-02-2006, 03:46 PM
That works sort of, except after it displays the error message it still attempts to run the form target php file.. It also only stops the entry once, if you try it again, it accepts it...

vwphillips
08-02-2006, 03:51 PM
<script language="JavaScript" type="text/javascript">
<!--

function CkNumbers(obj,nu){
var val=obj.value.replace(/\D/g,'');
if (val.length!=nu){
alert(nu+' Digits Required');
return false;
}
return true;

}
//-->
</script>



shows you how to verify the input
will need to know more if to integrate in you code

Please and Thank You are good



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum