If you've ever needed to collect Twitter or Instagram handles, then this input mask allows you to mask a field so that the @
symbol prepends the username value being provided.
// Provides an account handle input mask to receive Twitter and Instagram account handles
add_filter( 'gform_input_masks', function( $masks ) {
$masks['Account Handle'] = '@*?**************************';
return $masks;
} );
add_filter( 'gform_input_mask_script', function( $script, $form_id, $field_id, $mask ) {
if ( $mask == '@*?**************************' ) {
$script = "jQuery.mask.definitions['*']='[A-Z,a-z,0-9,_]';
jQuery('#input_{$form_id}_{$field_id}')
.mask('".esc_js( $mask )."',{placeholder:' '})
.on('keypress',function(e){if(e.which==13){jQuery(this).blur();}});";
}
return $script;
}, 10, 4 );