Skip to content

Instantly share code, notes, and snippets.

@sleepless-se
Last active November 11, 2021 08:54
Show Gist options
  • Save sleepless-se/db9fb8d42fabd0846f4b08b0d898072f to your computer and use it in GitHub Desktop.
Save sleepless-se/db9fb8d42fabd0846f4b08b0d898072f to your computer and use it in GitHub Desktop.
[text* yomigana] の日本語判定
// コンタクトフォーム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