Click to See Complete Forum and Search --> : need check on inputfield?


siebke
12-17-2003, 06:05 AM
Hye there.

I'm using a form validation script with checks on the required inputfields like:

if (name.value=='')
{
alert('Your name please');
name.focus()
return false;
}

The problem:

I want to do the same on another inp.field.
Except it has to check on 2 different things.

Meaning:

- if the value is only numeric and not alphabetic (for Example: 153679 would be correct and abcde or A3677 would'nt)

- next he should also check if the length of the value = 7 or > 7(greater)

Could someone please help fast?

Thank you very much...

regards Siebke.

Pittimann
12-17-2003, 09:18 AM
Hi!

You can try something like that:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function check(){
if (document.myForm.Name.value==''){
alert('Your name please');
document.myForm.Name.focus();
return false;
}
else if (isNaN (parseInt(document.myForm.Number.value))||document.myForm.Number.value.length<7){
alert('Only numbers allowed - min. length 7 places');
return false;
}
else{
return true;
}
}
//-->
</script>
</head>
<body>
<form name="myForm">
<input type="text" name="Name"><br>
<input type="text" name="Number"><br>
<input type="button" value="Check" onClick="check()">
</body>
</html>

Cheers - Pit

siebke
12-17-2003, 10:40 AM
Thanks Pitt.

I'll try this first

regards, siebke

siebke
12-19-2003, 02:48 AM
TNX Pitti;

It worked out perfectly

fredmv
12-19-2003, 11:33 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
<script type="text/javascript">
//<![CDATA[
function verifyInput()
{
if(/^\d{7}/g.test(document.forms[0][0].value)) return true;
else
{
alert('You must enter at least 7 digits.');
return false;
}
}
//]]>
</script>
</head>
<body>
<form action="#" onsubmit="verifyInput();">
<input type="text" />
<input type="submit" value="Submit" />
</form>
</body>
</html>