LoginSignup
11
9

More than 5 years have passed since last update.

【正規表現】カラーコードのバリデーション

Last updated at Posted at 2015-07-07

仕事で使う機会があったので。

  • 3桁もしくは6桁のカラーコードに一致
^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$
  • rgb形式に一致
^rgb\(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\,\s?){2}(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\)$
  • rgba形式に一致
^rgba\(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\,\s?){3}(0|0?\.\d+|1|1\.0+)\)$
  • hsla形式に一致
^hsla\((\d|[1-9]\d|[1-2]\d\d|3[0-5]\d|360)\,\s?((\d|[1-9]\d|100)\%\,\s?){2}(0|0?\.\d+|1|1\.0+)\)$

なんかもっとうまい感じにできないかなー
おしえてえろい人!!

11
9
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
11
9