I have been attempting to write a short script to validate a form value (mn) to make sure it meets the format of a valid 10 digit phone number.
I have been teaching myself online but still have a long way to go. Can anyone give me some clues as to how to fix the following problems....
*Pressing enter bypasses the validation and submits the form
*After exiting to REDO the input, the validation continues.
I Am getting there slowly... very slowy! Just need pointing in the right direction.
Thanks
Steve
I have been teaching myself online but still have a long way to go. Can anyone give me some clues as to how to fix the following problems....
*Pressing enter bypasses the validation and submits the form
*After exiting to REDO the input, the validation continues.
Code:
<script language="JavaScript">
<!--
function validate()
{
var D=(document.smsform.mn.value);
alert('Value of D is'+D);
var size = D.length;
alert('length='+size);
if (size != 10)
{
alert('The number you entered only had '+size+' digits. It should have 10.');
redo();
}
else
{
for (var i=1;i<D.length+1;i++)
{
var val=D.substring(i-1,i);
alert('Character # '+i+' = '+D.substring(i-1,i)+' - has a value of '+val);
var maxi='9';
var mini='0';
if (val<mini || val>maxi)
{
alert(D.substring(i-1,i)+' is not a valid character for a mobile phone. Please enter the number again.');
redo();
}
}
}
}
function redo()
{
alert('REDO form');
//* reset form for retry
return;
}
// -->
</script>
I Am getting there slowly... very slowy! Just need pointing in the right direction.
Thanks
Steve