Addressing a class while using Validation plugin

Addressing a class while using Validation plugin

i have the following validation code which works fine for limited fields.

I ahve a field for phone number where users can add any number of fields to add more phone numbers.
but am using a framework which follows certain conventions.

So wanna add a class to that input field and validate the input fields with that class. am not able to do it. please help

  1. $(function () {
  2.     $("form").validate({
  3.         "RestaurantName": [{
  4.             "rule": "\/^[\\s\\S]{2,}$\/",
  5.             "message": "Restaurant name should be of min 2 characters"
  6.         }],
  7.         "RestaurantStreet": [{
  8.             "rule": "\/^[\\s\\S]{5,}$\/",
  9.             "message": "Please Enter a proper Address"
  10.         }],
  11.         "RestaurantStreetExtra": [{
  12.             "rule": "\/^[\\s\\S]{5,}$\/",
  13.             "message": "Please Enter a proper Address",
  14.             "allowEmpty": true
  15.         }],
  16.         "RestaurantZipcode": [{
  17.             "rule": "\/^[+-]?[0-9|.]+$\/",
  18.             "message": "Zipcode should be a number"
  19.         },
  20.         {
  21.             "rule": "\/^.{6,6}$\/",
  22.             "message": "Zipcode should be 6 digits long",
  23.             "allowEmpty": true
  24.         }],
  25.         "RestaurantEmail": [{
  26.             "rule": "\/^([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+$\/",
  27.             "message": "Please enter a correct Email address",
  28.             "allowEmpty": true
  29.         }],
  30.         "RestaurantUrl": [{
  31.             "rule": "\/^(?:(?:https?|ftps?|file|news|gopher):\\\/\\\/)?(?:(?:(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])|(?:[a-z0-9][-a-z0-9]*\\.)*(?:[a-z0-9][-a-z0-9]{0,62})\\.(?:(?:[a-z]{2}\\.)?[a-z]{2,4}|museum|travel))(?::[1-9][0-9]{0,3})?(?:\\\/?|\\\/([\\!\"\\$&'\\(\\)\\*\\+,-\\.@_\\:;\\=\\\/0-9a-z]|(%[0-9a-f]{2}))*)?(?:\\?([\\!\"\\$&'\\(\\)\\*\\+,-\\.@_\\:;\\=\\\/0-9a-z]|(%[0-9a-f]{2}))*)?(?:#([\\!\"\\$&'\\(\\)\\*\\+,-\\.@_\\:;\\=\\\/0-9a-z]|(%[0-9a-f]{2}))*)?$\/i",
  32.             "message": "Please enter a correct website address",
  33.             "allowEmpty": true
  34.         }],
  35.         "RestaurantdetailAvgCost": [{
  36.             "rule": "\/^[+-]?[0-9|.]+$\/",
  37.             "message": "Please enter the Avg Cost",
  38.             "allowEmpty": true
  39.         },
  40.         {
  41.             "rule": "\/^[\\s\\S]{2,}$\/",
  42.             "message": "Please Enter a 2 digit number.",
  43.             "allowEmpty": true
  44.         }],
  45.         "RestaurantdetailHomeDeliveryDetails": [{
  46.             "rule": "\/^[\\s\\S]{5,}$\/",
  47.             "message": "Content should be min 5 characters",
  48.             "allowEmpty": true
  49.         }],
  50.         "RestaurantdetailReview": [{
  51.             "rule": "\/^[\\s\\S]{10,}$\/",
  52.             "message": "Review should have atleast 10 characters long",
  53.             "allowEmpty": true
  54.         }],
  55.         "Restaurantphone0Number": [{
  56.             "rule": "\/^.{8,10}$\/",
  57.             "message": "Please enter the phone number. fixed line = 8 digits, cellphone = 10 digits",
  58.             "allowEmpty": true
  59.         }],
  60.         "phone": [{
  61.             "rule": "\/^.{8,10}$\/",
  62.             "message": "Please enter the phone number. fixed line = 8 digits, cellphone = 10 digits",
  63.             "allowEmpty": true
  64.         }],
  65.         "Restaurantphone1Number": [{
  66.             "rule": "\/^.{8,10}$\/",
  67.             "message": "Please enter the phone number. fixed line = 8 digits, cellphone = 10 digits",
  68.             "allowEmpty": true
  69.         }]
  70.     }, {
  71.         "root": "\/bakasura\/",
  72.         "watch": []
  73.     })
  74. });
As you see in line 55 the id name is Restaurantphone0Number  and similarly in line 65 Restaurantphone1Number. to have dynamic fields i wanna replace this many rules with one rule n address the class i assign for it.


  1. <input type="text" id="Restaurantphone0Number" value="" name="data[Restaurantphone][0][number]" >
i want to address the input with the class phone as shown below

  1. <input type="text" id="Restaurantphone2Number" value="" class="phone" name="data[Restaurantphone][2][number]">