フリガナ(カタカナ)チェック

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>フリガナ(カタカナ)チェック</title>
  6. <body>
  7. <h1>フリガナ(カタカナ)チェック</h1>
  8. <script type="text/javascript">
  9.   function checkOfInputText()
  10.   {
  11.     if (checkInputChar(document.getElementById("InputText").value) == true)
  12.     {
  13.       alert("ok");
  14.     }
  15.     else
  16.     {
  17.       alert("ng");
  18.     }
  19.   }
  20.   
  21.   // 文字のチェック
  22.   function checkInputChar(str)
  23.   {
  24.     // 範囲指定できない文字の削除
  25.     DelTemporary = deleteSelectChar(str, new Array(" ", " ", "・", "-", "ー"));
  26.     
  27.     // 全角・半角の英数字を削除
  28.     KanaTemporary = DelTemporary.replace(/[A-Za-z0-9A-Za-z0-9]/g, "");
  29.     
  30.     temporary = KanaTemporary;
  31.     
  32.     // 残った文字でカタカナチェック
  33.     for (i = 0; i < temporary.length; i++)
  34.     {
  35.       if (temporary.charCodeAt(i) < 0x30A1 || 0x30F6 < temporary.charCodeAt(i))
  36.       {
  37.         return false;
  38.       }
  39.     }
  40.     return true;
  41.   }
  42.   // 文字の削除
  43.   function deleteSelectChar(str, delAry)
  44.   {
  45.     endDelStr = str;
  46.     for (i = 0; i < delAry.length; i++)
  47.     {
  48.       endDelStr = endDelStr.replace(new RegExp(delAry[i], "g"), "")
  49.     }
  50.     return endDelStr;
  51.   }
  52. </script>
  53. <p>
  54. formとかである「フリガナ」のチェック。英数字や一部記号、空白もOKにする。<br />
  55. ※ヴ・ヵ・ヶと対応するひらがなが無いのでカタカナでチェック
  56. </p>
  57. <input type="text" value="" id="InputText" />
  58. <input type="button" value="フリガナチェック" onclick="checkOfInputText()" /><br />
  59. <small>※カタカナ、半角・全角空白、半角・全角数字、半角・全角英語(大文字・小文字)、「・(中黒)」、「ー(長音記号)」、「-(ハイフン)」のみok</small>
  60. <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
  61. <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
  62. <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
  63. </div>
  64. <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
  65. Copyright &copy; 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
  66. </div>
  67. </body>
  68. </html>