Kermit Piper wrote:
Hello,
I know, using client-side validation to validate form data by looping
through a SQL Server table isn't the best way in terms of security.
But, is there a way to compare the form object value against
values in a flat file, like with arrays? I have a flat file of 1300
values I'd like to be able to use as a comparator against the value I
grab from the form to validate the input.
Probably the fastest way to validate a large number of values is to use
an Object object and have your 1300 values as properties of the object,
then use for..in, e.g.:
var validNames = {
name0001 :'',
name0002 :'',
name0003 :'',
...
name1299 :'',
name1300 :''
};
Then you can check:
if ( someEntry in validNames ){
// someEntry is valid
}
However you need to weigh up the time spent downloading the object to
the client vs the time that might be spend going back to the server and
validating there in the first place.
I have also successfully used an array where an index is created based
on the first character of each string, then use the first character of
the entered string to get the index. Loop through the array from that
point grabbing only the elements that match the entered text and present
them as options. Users then get an ever-diminishing list of options to
select.
Even with a poor distribution of first letters, the lookup loop is
usually still very fast.
--
Rob