I'm too late, but since I typed it anyway:
<HTML>
<HEAD><TITLE>Test</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function check(str) {
for(err="", i=0; i<str.length; i++, err+="_") {
ch = str.charAt(i);
if(ch < '0' || ch > '9') {
alert("Bad number:\n"+err+"v\n"+str+"
return;
}
}
alert("Good number:\n"+str);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME=f>
<INPUT NAME=num SIZE=10>
<INPUT TYPE=BUTTON VALUE=Check onClick='check(f.num.value
</FORM>
</BODY>
</HTML>
Main Topics
Browse All Topics





by: pmcintosPosted on 1997-07-31 at 09:24:22ID: 1268791
I have a little trouble understanding the question...
I beleive that you need a way to examine a string and see if it contains a certain number or not...
This is the way I would solve this problem:
var checkvar = "200000";
//get this next variable from the form.
var str = document.Form.str.value;
for ( var i = 0; i < str.length; i ++ ) {
if ( str.substring( i, (i + checkvar.length) ) {
alert ( "Found " + checkvar + " in the string searched!");
}
}
If you are looking for particluar number that is the way you would do it. If you need to inspect for any number then you have to use another for loop inside the first one and just compare each character of the checkvar ( say checkvar = "0123456789" ) with each character of the string you want to check.
If this isn't the question you asked then e-mail me a revised version and I'll try to help with that.
Pete