On Feb 6, 7:29 am, Michael <mich...@vermontsnows.com> wrote:
> Thank you all - Kangax's low profile technique works like a champ.
>
> Walter Lee: Regular expressions hurt my head. I will get there one
> day.
>
> The actual thing I am working on take about 100 alpha/numeric
> sequences of no real logical order... so making it in regular
> expression would take far longer (for me) then juts stubbing the 100
> sequences in there.
Not sure what you mean by "stubbing" here, but regular expressions are
pretty quick. If you supply the set of values as a string using a
delimiter (a space seems appropriate here), you can use something very
similar to the standard "hasClass" function:
var checkValid = (function() {
var validSet = "V30000 B47242 V54000";
return function(val) {
return RegExp('^|\\s' + val + '\\s|$').test(validSet);
}
})();
alert( checkValid('V54000') );
To make the validSet more accessible for initialisation, you might do:
var checkValid = (function(validSet) {
return function(val) {
return RegExp('/^|\\s' + val + '\\s|$').test(validSet);
}
})("V30000 B47242 V54000");
To change the set of valid values, replace the string in the call.
The advantage here is that you can put pretty much any space-delmited
value in the set of valid values and it will "work".
--
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---