Let's say I have a line of text like this
アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグ
I want to verify input is katakana or not so I use regex
'/^[゠ ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク グ ケ ゲ コ ゴ サ ザ シ ジ ス ズ セ ゼ ソ ゾ タ ダ チ ヂ ッ ツ ヅ テ デ ト ド ナ ニ ヌ ネ ノ ハ バ パ ヒ ビ ピ フ ブ プ ヘ ベ ペ ホ ボ ポ マ ミ ム メ モ ャ ヤ ュ ユ ョ ヨ ラ リ ル レ ロ ヮ ワ ヰ ヱ ヲ ン ヴ ヵ ヶ ヷ ヸ ヹ ヺ ・ ー ヽ ヾ ヿ⦅ ⦆ 。 「 」 、 ・ ヲ ァ ィ ゥ ェ ォ ャ ュ ョ ッ ー ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ン ゙]+$/'
Is there some way to compact that?
I know its hard code, before that I used ^[ァ-ヴーァ-ン゙゚]+$ but it not work in laravel request rule.
Your regex
ァ-ヴーァ-ン゙゚is correct, you just need to add/uto make it work.so the correct regex code is
or an example in the laravel validation :
The
/umodifier is for unicode supportYou can also use Unicode octal as regex range, an example for Katakana is
([\u30a0-\u30ff]*), but in php pcre\ushould be changed to\xlike:Also, you can check this gist for other katakana and hiragana regex. Example:
Regex for matching full-width Katakana (zenkaku 全角)
Regex for matching half-width Katakana (hankaku 半角)