5 月 212009
 

Regular Expression 判斷 1-99 | Tsung’s Blog

剛開始想 ^[1-9]?\d$ 就解決了, 但是又有 0 的狀況, 突然覺得似乎不太容易, 隨手 Google 找 regex 1-99, 沒想到有這問題的還真不少.

Regex 判斷 1-99 的寫法

參考此篇文章: regex for range from 1-99

解法: (下述兩種都可以)

  • ^([1-9][0-9]?|)$
  • ^([1-9][0-9]?){0,1}$

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

CAPTCHA Image
Play CAPTCHA Audio
Reload Image