
jQuery(function($){
  
  $('#preactivate_loyalty').parents('form').validate({
    rules: {"preactivate[loyalty]":{"required":true,"regex":"^7[0-9]{9}$"},"preactivate[email]":{"required":true,"email":true}},
    messages: {"preactivate[loyalty]":{"required":"Requerido.","regex":"N&uacute;mero Inv&aacute;lido."},"preactivate[email]":{"required":"Requerido.","email":"E-mail incorrecto."}},
    wrapper: 'ul class=error_list',
    errorElement: 'li',
    errorPlacement: function(error, element) 
    {
     if(element.parents('.radio_list').is('*') || element.parents('.checkbox_list').is('*'))
     {
       error.prependTo( element.parent().parent().parent() );
     }
     else
     {
       error.prependTo( element.parent() );
     }
   }
  
  });
  
  
});

/* for some reason the jQuery Validate plugin does not incluce a generic regex method */
jQuery.validator.addMethod(
  "regex",
  function(value, element, regexp) {
      if (regexp.constructor != RegExp)
          regexp = new RegExp(regexp);
      else if (regexp.global)
          regexp.lastIndex = 0;
      return this.optional(element) || regexp.test(value);
  },
  "Invalid."
);
