Skip to content

Instantly share code, notes, and snippets.

@New0
Last active November 17, 2017 14:50
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/6f005622dd8cc02eaa72acd190decfa0 to your computer and use it in GitHub Desktop.
Save New0/6f005622dd8cc02eaa72acd190decfa0 to your computer and use it in GitHub Desktop.
Set a pattern for min and max length of fields, combined with the required field option.
<?php
//Use caldera_forms_field_attributes filter hook
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){
//REPLACE fld_******* BY YOUR OWN FIELD IDs
//Min and max 5
if( 'fld_4009904' === $field[ 'ID' ] ) {
$attrs[ 'pattern' ] = ".{5,5}";
}
//Min and max 10
if( 'fld_*******' === $field[ 'ID' ] ) {
$attrs[ 'pattern' ] = ".{10,10}";
}
return $attrs;
}, 20, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment