-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhtmlform1.html
More file actions
31 lines (31 loc) · 893 Bytes
/
htmlform1.html
File metadata and controls
31 lines (31 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<HTML>
<HEAD>
<TITLE>Test Input Validation</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function testResults (form) {
TestVar = isNumberString (form.inputbox.value)
if (TestVar == 1)
alert ("Congratulations! You entered only numbers");
else
alert ("Boo! You entered a string with non-numbers characters");
}
function isNumberString (InString) {
if(InString.length==0) return (false);
var RefString="1234567890";
for (Count=0; Count < InString.length; Count++) {
TempChar= InString.substring (Count, Count+1);
if (RefString.indexOf (TempChar, 0)==-1)
return (false);
}
return (true);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="myform">
Enter a string with numbers only:
<INPUT TYPE="text" NAME="inputbox" VALUE="">
<INPUT TYPE="button" NAME="button" Value="Click" onClick="testResults(this.form)" >
</FORM>
</BODY>
</HTML>