How to Add an Input Mask to the International Postal Code


Would you like to set up an input mask on the International Address Scheme Postal Code field? In this tutorial, we’ll show you the PHP snippet needed to add an input mask to the international Postal Code field.


By default, the Postal Code on the International Address will automatically accept any character. However, if you’d like to only allow certain characters in a certain format, an input mask on the field would be the best solution.

To create an input mask on the this field, simply add this code to your site.

  * Custom input mask for the address field's international scheme.
  * @link

function wpf_dev_address_field_properties( $properties, $field, $form_data ) {
    if($field['scheme'] === 'international'){
  	    $properties['inputs']['postal']['class'][]                  = 'wpforms-masked-input';
	    $properties['inputs']['postal']['data']['inputmask-mask']   = '999999';
	    $properties['inputs']['postal']['data']['inputmask-greedy'] = 'false';
  return $properties; 
 add_action( 'wpforms_field_properties_address', 'wpf_dev_address_field_properties', 10, 3 );

Now the postal code has an input mask to force the format of the postal code

And that’s all you need to add the input mask to the International Address Scheme’s Postal Code. Would you like to create a custom address scheme? Check out our article on How to Create Additional Schemes for the Address Field.

Filter Reference: wpforms_field_properties