1

I use custom validation for my field

<div class="control-group">
  <label class="control-label" for="region">Region*</label>
  <div class="controls">
    <input type="text" class="input-xlarge" id="region" name="region" minlength="1" maxlength="50" autocomplete="off">
  </div>
</div>

var regionsList = ["value1", "value2", ..., "value 80"];

$.validator.addMethod("validRegion", function (value, element, param) {
  return this.optional(element) || (param.indexOf(value) != -1); // ERROR IS HERE
}, "Please start to type and choose correct value");

$("#myform").validate({
  rules: {
    "region": {
      required: true,
      validRegion: regionsList
    },
 ...

What can be wrong at this line (please look for the line with comment ERROR IS HERE)? The error is Object doesn't support this property or method.

LA_
  • 19,823
  • 58
  • 172
  • 308
  • Yeah please tell the details. What's the error? – jsalonen Oct 18 '12 at 17:23
  • @pst, the line has been given, please look for the comment in the code. And I've added the error message. – LA_ Oct 18 '12 at 17:25
  • Not the answer but just in case... when declaring an object, make sure you don't have a ',' after the last property. IE7 and IE8 will give you an error. – VVV Oct 18 '12 at 17:31

1 Answers1

4

Array.indexOf is only supported on IE 9+. Since you are already using jQuery, you can use $.inArray (it will use Array.indexOf if its supported).

$.validator.addMethod("validRegion", function (value, element, param) {
  return this.optional(element) || ($.inArray(value, param) != -1);
}, "Please start to type and choose correct value");
gen_Eric
  • 223,194
  • 41
  • 299
  • 337