Skip to content

Instantly share code, notes, and snippets.

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/8186e9cb6020b3c565017df436208430 to your computer and use it in GitHub Desktop.
Save New0/8186e9cb6020b3c565017df436208430 to your computer and use it in GitHub Desktop.
Social security number pattern for Caldera Forms single line text fields
<?php
/*
* Validates fields only using a Social security number pattern like 999-99-999
* EDIT FIELDS IDS TO BE VALIDATED "fld_5675945", "fld_1648505"
*/
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){
$fields = ["fld_5675945", "fld_1648505"];
if( in_array( $field['ID'], $fields ) ){
$attrs[ 'pattern' ] = '^\d{3}-\d{2}-\d{4}';
}
return $attrs;
}, 20, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment