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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to validate a subset of numbers from a bigger set

Status
Not open for further replies.

pyttviper

MIS
May 15, 2001
37
0
0
US
I have a textbox which can hold a Road No. Range in the given format [10-15,17,20-25,28]

And I have two or three other textboxes in which I need to enter the subset of the range I entered in the Header Road No. Range. The first subset textbox might look like this [10-13], the second might be [14-15,17,20-25] and the third would be [28].

Now how do I make sure that the user entered all the valid Road No's in the subset textboxes that belonged to the Header Road No. And check if the user missed out on entering any of the numbrs mentioned in the Header Textbox.

Thanking in anticipation.

 
This script uses the ',' to split the values into arrays it then compares the values with those in the Range.

<html>
<head>
<title>
</title>
<script language=&quot;javascript&quot;>
function checkvalues(){
var marker = 0;
var range = document.forms['inputform'].road.value;
var roadtwo = document.forms['inputform'].road2.value;
var roadthree = document.forms['inputform'].road3.value;
var roadfour = document.forms['inputform'].road4.value;
rangearray = range.split(&quot;,&quot;);
roadtwoarray = roadtwo.split(&quot;,&quot;);
roadthreearray = roadtwoarray.concat(roadthree.split(&quot;,&quot;));
masterarray = roadthreearray.concat(roadfour.split(&quot;,&quot;));

for(var i=0;i<rangearray.length;i++){
marker = 0;
for(var p=0;p<masterarray.length;p++){
if(masterarray[p] == rangearray){
marker = 1;
}
}
if(marker != 1){
alert(&quot;item &quot;+ rangearray + &quot; is missing&quot;)
return false;
}

}



}
</script>
</head>
<body>
<form name='inputform'>
<input type=&quot;text&quot; name=&quot;road&quot;><br>
<input type=&quot;text&quot; name=&quot;road2&quot;><br>
<input type=&quot;text&quot; name=&quot;road3&quot;><br>
<input type=&quot;text&quot; name=&quot;road4&quot;><br>
</form>
<input type=&quot;submit&quot; onClick=&quot;javascript:checkvalues();&quot;>
</body>
</html>
 
Tek tips changed your script, the rangearray item is indicated with i like so: rangearray[p] I use p here because if I use i it looks like this irretating isn't it.
 
The solution put up here by Leo Farmer does not split by
'-' character.

In the given question, the bigger range textbox values were exactly matched by the subset textboxes though not in the same order as entered in the bigger range textbox.

I think, the question here is to validate if the combination of values in the subsets exactly matches the values in the bigger range, with all the subset textboxes being made use of to arrive at the number values entered in the bigger range. The user could enter any combinations in the subset textboxes and it has to exactly match the main set with all subset textboxes being made use of.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top