Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Computing help - string length help!!!?
i have found this coding:
<script language="JavaScript1.2">
function checkpostal(){
var re4digit=/^\d{4}$/ //regular expression defining a 4 digit number
if (document.myform.myinput.value.search(re4digit)==-1) //if match failed
alert("Please enter a valid 4 digit number inside form")
}
</script>
<form name="myform">
<input type="text" name="myinput" size=15>
<input type="button" onClick="checkpostal()" value="check">
</form>
i'm supposed to add it to the following coding so the examination number will only be accepted when its 4 numbers long. how do it. here is the coding:
<html>
<head>
<title>Exam entry</title>
<script language="javascript" type="text/javascript">
function validateForm() {
var result = true;
var msg="";
if (document.ExamEntry.name.value=="") {
msg+="You must enter your name \n";
document.ExamEntry.name.focus();
document.getElementById('name').style.color="red";
result = false;
}
if (document.ExamEntry.subject.value=="") {
msg+="You must enter the subject \n";
document.ExamEntry.subject.focus();
document.getElementById('subject').style.color="red";
result = false;
}
if (document.ExamEntry.Examination_Number.value=="") {
msg+="You must enter the examination number \n";
document.ExamEntry.Examination_Number.focus();
document.getElementById('Examination_Number').style.color="red";
result = false;
}
if(msg==""){
return result;
}
{
alert(msg)
return result;
}
var re4digit=/^\d{4}$/ //regular expression defining a 4 digit number
if (document.ExamEntry.Examination_number.value.search(re4digit)==-1) //if match failed
alert("Please enter a valid 4 digit number")
}
</script>
</head>
<body>
<h1>Exam Entry Form</h1>
<form name="ExamEntry" method="post" action="success.html">
<table width="50%" border="0">
<tr>
<td id="name">Name</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td id="subject">Subject</td>
<td><input type="text" name="subject" /></td>
</tr>
<tr>
<td id="Examination_Number">Examination Number</td>
<td><input type="text" name="Examination_Number" /></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit" onclick="return validateForm();" /></td>
<td><input type="reset" name="Reset" value="Reset" /></td>
</tr>
</table>
</form>
</body>
</html>
1 Answer
- 1 decade ago
I would like to say that you put it between the </head> and <body> , but im not a wiz at this! ^.^' Lemme know if it worked ;P