2
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.

【正規表現】はじめの数文字は英字、それ以降は数字で制限する

Last updated at Posted at 2021-01-08

内容に不備があります😓
コメント欄を参考にしてください(ご指摘ありがとうございます。。)。

たとえば

A012345

みたいな形式の文字列で制限したい。
今回は『最初1文字は英大文字、それに続く数字は6文字』というルールを作る。
たぶん他の言語でもいけると思いますが、PHPで書くことを想定します。

正規表現を書く

/^[A-Z{1}]+[0-9{6}]+$/

英大文字(1文字)+数字(6文字)』と指定しています。単純ですね。
こちらで検証できます。↓

PHP: preg_match() / JavaScript: match() 正規表現チェッカー ver3.1
http://okumocchi.jp/php/re.php

2
0
5

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