well, I am more of a PHP person, and my JS skills are close to none when it comes to any JS other than simple design related operations , so excuse me if I am asking the obvious .
the following operations would be a breeze in PHP (and might also be in JS - but I am fighting with unfamiliar syntax here ...)
It is some sort of input validation
var ar = ["BRS201103-0783-CT-S", "MAGIC WORD", "magic", "Words", "Magic-Word"];
jQuery(document).ready(function() {
jQuery("form#searchreport").submit(function() {
if (jQuery.inArray(jQuery("input:first").val(), ar) != -1){
jQuery("#contentresults").delay(800).show("slow");
return false;
}
This question has 2 parts .
- 1 - how can I make it possible for the array to be case insensitive ?
E.g. - BRS201103-0783-CT-S
will give the same result as brs201103-0783-ct-s
AND Brs201103-0783-CT-s
or MAGIC magic Magic MaGIc
basically i need something like ignoreCase() for array , but I could not find any reference to that in jQuery nor JS...
I tried toLowerCase()
- but It is not working on the array (ittirating??) and also, would it resolve the mixed case ?
- 2 - How can I make the function to recognize only parts or combinations of the elements ?
E.g. - if one types only "word"
, I would like it to pass as "words"
, and also if someone types "some word"
it should pass (containing "word" )
if (jQuery.inArray(jQuery("input:first").val().toLowerCase(), ar) != -1){
, the second part of the questions seems a little too broad. What are the specific rules?word
is contained inwords
ok, butsome word
is not contained inwords
. – Bullishsome word
containsword
and alsowords
containsword
(part of string...) – Denesedengueval().toLowerCase()
will work on a word like "magic/MAgIc" - but now it returns false the stringBRS201103-0783-CT-S
no matter how I enter it (small case letters , upper case or mixed.. – Denesedenguemagic
is lowercase in your array, whileBRS201103-0783-CT-S
is not. Check alex's answer, he posted a simple function to pass your whole array to lowercase.:)
– Bullish