Created
February 11, 2020 09:29
-
-
Save yuichi-e/dd64baa18a621783a3a70830f00ea898 to your computer and use it in GitHub Desktop.
cf7カスタムバリデーション(名前の日本語を強制) #wordpress
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
// cf7カスタムバリデーション(名前の日本語を強制) | |
function wpcf7_validate_spam_message($result, $tag) | |
{ | |
$value = str_replace(array(PHP_EOL, ' '), '', esc_attr($_POST['your-name'])); // この行と | |
if (!empty($value)) { | |
if (preg_match('/^[!-~]+$/', $value)) { //正規表現で日本語以外を指定 | |
$result['valid'] = false; | |
$result['reason'] = array('your-name' => 'お名前は日本語で入力してください'); // この行でフィールドを指定 | |
} | |
} | |
return $result; | |
} | |
add_filter('wpcf7_validate', 'wpcf7_validate_spam_message', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment