indexOf an array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gozil
    New Member
    • Jul 2007
    • 42

    indexOf an array?

    Hello, i was wondering if its possible to check the my value against an array?
    Lets say I have 5 characters i dont want the user to have in the input field so instead of writeing like this:

    [CODE=javascript]my_value.indexO f('first') == -1
    my_value.indexO f('second') == -1
    my_value.indexO f('3rd') == -1
    my_value.indexO f('4th') == -1
    my_value.indexO f('5th') == -1 and so on...

    I would write like this:
    var array_value = new Array("first", "second", "3rd", "4th" ,"5th");
    value.indexOf(a rray_value) == -1[/CODE]

    I tried that but couldnt get it to work, so is it possible to do this?
    Last edited by gits; Jul 30 '07, 06:38 AM. Reason: added CODE tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

    try something like the following:

    [CODE=javascript]
    var array_value = new Array("first", "second", "3rd", "4th" ,"5th");

    for (var i = 0; i < array_value.len gth; i++) {
    if (value.indexOf( array_value[i]) == -1) {
    // do something
    } else {
    // do something other
    }
    }
    [/CODE]
    kind regards

    Comment

    • Gozil
      New Member
      • Jul 2007
      • 42

      #3
      Thanks, that will do it

      Comment

      Working...