Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to validate a form value.

Status
Not open for further replies.

skipyb

Programmer
Dec 24, 2001
5
AU
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.


Code:
<script language=&quot;JavaScript&quot;>
<!-- 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top