Skip to content

Instantly share code, notes, and snippets.

@sleepless-se
Created November 11, 2021 08:52
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 sleepless-se/c6addb352c783737d312b5ec8cafaf67 to your computer and use it in GitHub Desktop.
Save sleepless-se/c6addb352c783737d312b5ec8cafaf67 to your computer and use it in GitHub Desktop.
コンタクトフォーム7漢字入力判定
// コンタクトフォーム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