Home / Admin / How to Add an Input Mask to the International Postal Code
Duplicate Snippet

Embed Snippet on Your Site

How to Add an Input Mask to the International Postal Code

<10
Code Preview
php
<?php
/*
  * Custom input mask for the address field's international scheme.
  *  
  * @link https://wpforms.com/developers/how-to-add-an-input-mask-to-the-international-postal-code
*/
 
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';
        $properties[ 'inputs' ][ 'postal' ][ 'data' ][ 'rule-empty-blanks' ] = true;
 
    }
 
  return $properties; 
 
}
 add_action( 'wpforms_field_properties_address', 'wpf_dev_address_field_properties', 10, 3 )

Comments

Add a Comment