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
- $(function () {
- $("form").validate({
- "RestaurantName": [{
- "rule": "\/^[\\s\\S]{2,}$\/",
- "message": "Restaurant name should be of min 2 characters"
- }],
- "RestaurantStreet": [{
- "rule": "\/^[\\s\\S]{5,}$\/",
- "message": "Please Enter a proper Address"
- }],
- "RestaurantStreetExtra": [{
- "rule": "\/^[\\s\\S]{5,}$\/",
- "message": "Please Enter a proper Address",
- "allowEmpty": true
- }],
- "RestaurantZipcode": [{
- "rule": "\/^[+-]?[0-9|.]+$\/",
- "message": "Zipcode should be a number"
- },
- {
- "rule": "\/^.{6,6}$\/",
- "message": "Zipcode should be 6 digits long",
- "allowEmpty": true
- }],
- "RestaurantEmail": [{
- "rule": "\/^([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+$\/",
- "message": "Please enter a correct Email address",
- "allowEmpty": true
- }],
- "RestaurantUrl": [{
- "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",
- "message": "Please enter a correct website address",
- "allowEmpty": true
- }],
- "RestaurantdetailAvgCost": [{
- "rule": "\/^[+-]?[0-9|.]+$\/",
- "message": "Please enter the Avg Cost",
- "allowEmpty": true
- },
- {
- "rule": "\/^[\\s\\S]{2,}$\/",
- "message": "Please Enter a 2 digit number.",
- "allowEmpty": true
- }],
- "RestaurantdetailHomeDeliveryDetails": [{
- "rule": "\/^[\\s\\S]{5,}$\/",
- "message": "Content should be min 5 characters",
- "allowEmpty": true
- }],
- "RestaurantdetailReview": [{
- "rule": "\/^[\\s\\S]{10,}$\/",
- "message": "Review should have atleast 10 characters long",
- "allowEmpty": true
- }],
- "Restaurantphone0Number": [{
- "rule": "\/^.{8,10}$\/",
- "message": "Please enter the phone number. fixed line = 8 digits, cellphone = 10 digits",
- "allowEmpty": true
- }],
- "phone": [{
- "rule": "\/^.{8,10}$\/",
- "message": "Please enter the phone number. fixed line = 8 digits, cellphone = 10 digits",
- "allowEmpty": true
- }],
- "Restaurantphone1Number": [{
- "rule": "\/^.{8,10}$\/",
- "message": "Please enter the phone number. fixed line = 8 digits, cellphone = 10 digits",
- "allowEmpty": true
- }]
- }, {
- "root": "\/bakasura\/",
- "watch": []
- })
- });
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.
- <input type="text" id="Restaurantphone0Number" value="" name="data[Restaurantphone][0][number]" >
i want to address the input with the class phone as shown below
- <input type="text" id="Restaurantphone2Number" value="" class="phone" name="data[Restaurantphone][2][number]">