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 1 year has passed since last update.

電話番号の正規表現

Last updated at Posted at 2023-11-03

電話番号の正規表現

※携帯番号は除く

<VB.NETの場合>

・ハイフンの有無に関係なくチェック可能

 例:***-***-******-****-****0120-***-*** など

^(\d{2}-?\d{4}-?|\d{3}-?\d{3}-?|\d{4}-?\d{2}-?|\d{5}-?\d{1}-?|\d{6}-?|\d{1,4}-?)\d{4}|0120[-]?\d{3}[-]?\d{3}$
  • \d:0-9の半角数字
  • -?-があってもなくても良い
  • |:または(orと同じ意味)
  • {2}:2桁(文字数)
  • ():グループ分け
    • (\d{2}-?\d{4}-?|\d{3}-?\d{3}-?|\d{4}-?\d{2}-?|\d{5}-?\d{1}-?|\d{6}-?|\d{1,4}-?)
      で1つのグループになっている。

  • \d{2}-?\d{4}-?**-****または******が該当する。(*は半角数字)
  • \d{1,4}-?:半角数字1桁~4桁までが該当する。{最小桁数、最大桁数}

・半角数字のみ

 例:01234567890

^[0-9]+$
  • +:[0-9]を1回以上繰り返す。

10桁の半角数字

 例:0123456789

 ^[0-9]{10}$
  • {10}:10桁(文字数)

参考サイト

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?