Created
January 7, 2020 20:20
-
-
Save New0/8186e9cb6020b3c565017df436208430 to your computer and use it in GitHub Desktop.
Social security number pattern for Caldera Forms single line text fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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