Skip to content

Instantly share code, notes, and snippets.

@sleepless-se
Last active November 11, 2021 08:55
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/472410a61df0d1b06d8c97ace0e598a2 to your computer and use it in GitHub Desktop.
Save sleepless-se/472410a61df0d1b06d8c97ace0e598a2 to your computer and use it in GitHub Desktop.
[textarea* yomigana] の日本語入力判定
```
// コンタクトフォーム7 日本語判定 ここから
add_filter('wpcf7_validate_textarea', 'wpcf7_validate_yomigana', 11, 2);
add_filter('wpcf7_validate_textarea*', '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