Created
November 11, 2021 08:52
-
-
Save sleepless-se/c6addb352c783737d312b5ec8cafaf67 to your computer and use it in GitHub Desktop.
コンタクトフォーム7漢字入力判定
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
// コンタクトフォーム7 日本語判定 ここから | |
add_filter('wpcf7_validate_text', 'wpcf7_validate_yomigana', 11, 2); | |
add_filter('wpcf7_validate_text*', 'wpcf7_validate_yomigana', 11, 2); | |
function wpcf7_validate_yomigana($result,$tag){ | |
$tag = new WPCF7_Shortcode($tag); | |
$name = $tag->name; | |
$value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : ""; | |
// 入力項目名が、'yomigana'の場合に実行 | |
if ( $name === "yomigana") { | |
// ひらがな・カタカナ以外だった場合 | |
if(!preg_match("/[亜-熙]/u", $value)) { | |
$result->invalidate($tag, "フリガナを入力してください。"); | |
} | |
} | |
return $result; | |
} | |
// コンタクトフォーム7 日本語判定 ここまで |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment