Skip to content

Instantly share code, notes, and snippets.

@New0
Created February 19, 2020 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save New0/f09ca32debb209cf57cadef7dd180a60 to your computer and use it in GitHub Desktop.
Save New0/f09ca32debb209cf57cadef7dd180a60 to your computer and use it in GitHub Desktop.
Set an html5 pattern on a Caldera Forms field
<?php
/*
* HTML5 Pattern to limiot input field to 8 alphanumeric (only capitals) characters
*/
add_filter( 'caldera_forms_field_attributes', function($attrs, $field){
//IMPORTANT - Change your field ID
if ( 'fld_1234' === $field[ 'ID'] ) {
$attrs[ 'pattern' ] = '[A-Z0-9]{8}';
}
return $attrs;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment