Additional validation function

Adding additional validation functions to fields in WPPizza -> Order form

There are a number of additional javascript validation functions in-built into the plugin. However, aside from the default ones you can already select you have to selectively enable the ones that are of use to you.

The following functions are available (please see the jquery validation documentation for details on each)

  • alphanumeric
  • maxWords
  • minWords
  • rangeWords
  • accept
  • bankaccountNL
  • bankorgiroaccountNL
  • bic
  • cifES
  • cpfBR
  • creditcard
  • creditcardtypes
  • currency
  • dateFA
  • dateITA
  • dateNL
  • extension
  • giroaccountNL
  • iban
  • integer
  • ipv4
  • ipv6
  • lettersonly
  • letterswithbasicpunc
  • mobileNL
  • mobileUK
  • nieES
  • nifES
  • notEqualTo
  • nowhitespace
  • parameters
  • phoneNL
  • phoneUK
  • phoneUS
  • phonesUK
  • postalCodeCA
  • postalcodeBR
  • postalcodeIT
  • postalcodeNL
  • postcodeUK
  • require_from_group
  • skip_or_fill_minimum
  • stateUS
  • time
  • time12h
  • url2
  • vinUS
  • zipcodeUS
  • ziprange
  • decimal /* wppizza plugin custom added methods – not a jqueryvalidation rule */

wppizza_filter_validation_rules

enabling one of the above rules

@param: array (all validation rules)
@return: array

example:

	add_filter('wppizza_filter_validation_rules','my_function');
	//to enable an exiting  rule above - let's say 'phoneUS'
	function my_function($validation_rules){
		$validation_rules['phoneUS']['enabled'] = true;
	return $validation_rules;
	}

creating and adding your own rules

example:

	/*-----------------------php (see also https://docs.wp-pizza.com/developers/?section=filters-actions-functions)-----------------------------------------------*/
	//to add your own rule - let's say 'my_rule'
	add_filter('wppizza_filter_validation_rules','my_function');
	function my_function($validation_rules){
		$validation_rules['my_rule']= array( 'lbl'=> 'My Rule', 'parameters'=>false, 'callback'=>false, 'enabled'=>true);
	return $validation_rules;
	}


	/*-----------------------js-----------------------------------------------*/
	// then add the rule like so via wp_footer action hook (or add it to an already existing js file)
	// adjust the validation pattern as appropriate for your validation rule

	jQuery(document).ready(function($){
		$.validator.methods.my_rule = function (value, element) {
   			return this.optional(element) || /^(?:\d+|\d{1,3}(?:[\s\.,]\d{3})+)(?:[\.,]\d+)?$/.test(value);
		}
		// adding a custom error message if validation fails instead of the default (not actually tested but should work just the same)
		jQuery.extend(jQuery.validator.messages, {
			my_rule: 'some error message,
		})
	});