Hi,
so yet more problems for me with javascript!!
What I am attempting to do is create a phone number validator which checks;
1.If there is nothing entered into the field return with an alert.
2.If there are any spaces within the text entered into the field, delete them.
3.After the spaces have been deleted check if the entered data is a number using isnan(), and check that the number is no shorter than 11 digits. Then return true! - if the number is shorter than 11 digits return with a alert message.
Number 1 isnt a problem, but to be honest I dont have clue how to do numbers 2 and 3. Anyone had any experience doing this before and if so how should i fix it??
- Code: Select all
<script type="text/javascript">
<!--
function validate_form ( )
{
if (document.callmeback_form.name.value == "" )
{
alert ( "Please enter your name." );
document.callmeback_form.name.focus();
document.callmeback_form.name.style.background = '#FF8600';
document.callmeback_form.name.style.border= "1px solid #A5ACB2";
document.callmeback_form.name.style.width= "132px";
document.callmeback_form.name.style.height= "15px";
return false;
}
if (document.callmeback_form.telephone.value == "" )
{
alert ( "Please enter your number (inc. area code)." );
document.callmeback_form.telephone.focus();
document.callmeback_form.telephone.style.background = '#FF8600';
document.callmeback_form.telephone.style.border= "1px solid #A5ACB2";
document.callmeback_form.telephone.style.width= "132px";
document.callmeback_form.telephone.style.height= "15px";
return false;
}
var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
if (document.callmeback_form.telephone(isNaN(parseInt(stripped))))
{
error = "The phone number contains illegal characters.";
}
}
//-->
</script>
<form class="register" action="callmeback-action.php" method="post" name="callmeback_form" onsubmit="return validate_form ( );"><input type="hidden" name="previous" value="<?PHP echo $_SERVER["HTTP_REFERER"]; ?>" />
<div id="regtype">
<div><label for="radnow">Call me NOW:</label><input type="radio" name="when" id="radnow" value="now" class="radio" checked="checked" onclick="regenable();" /></div>
<div><label for="rad30min">Call me in 30 Minutes:</label><input type="radio" name="when" id="rad30min" value="30min" class="radio" onclick="regenable();" /></div>
<div><label for="radtime">Call me at a specific time:</label><input type="radio" name="when" id="radtime" value="time" class="radio" onclick="regenable();" /></div>
</div>
<div>
<div><label for="name" id="namelabel">Name:</label><input name="name" id="name" type="text" class="text" /></div>
<div><label for="telephone" id="telephonelabel">Telephone No:</label><input name="telephone" id="telephone" type="text" class="text" /></div>