0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

空白文字のみが連続する文字列を禁止するための正規表現

0
Last updated at Posted at 2020-09-25

フォームへの入力で空欄を禁止することはあります。
空白文字のみが入力された文字列も禁止するためには、以下の正規表現を使います。
空白と通常の文字の合わさった文字列は通しますが、空白文字のみ場合は弾きます。

<input type ="text" pattern=".*\S+.*"/>
 const ok1 ="a";//通る
 const ok2 =" a "; //通る
 const ok3 ="a ";//通る
 const NG ="   ";//通らない

全角スペースはページの文字コードがUTF-8であれば、空白文字の範囲に含まれます。

完全に備忘録レベルなので、正しさについては保証しません。
ただ、多分動きます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?