1
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 3 years have passed since last update.

正規表現で半角スペースを許容

Posted at

ケース

半角英字で入力するフォームで半角スペースがバリデーションにかかってしまっていた

対処

正規表現に (半角スペース)を含める

/^[a-zA-Z ]*$/

説明

正規表現において半角スペースはエスケープの必要がなく、
通常の文字と同様に扱うことができる。
そのため、半角スペースをそのまま正規表現に含めてあげれば対象にできる。

参考

1
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
1
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?