Regular expression for decimals as well as integers with a range limit

By July 28, 2016PHP

This is an example for regular expression which allow both decimals as well as integers with a range limit of 40-180
Regex Pattern:

/^([4-8][0-9]|[4-8][0-9]\d{0,9}(\.\d{1,3})|9[0-9]\d{0,9}(\.\d{1,3})|1[0-7][0-9]|1[0-7][0-9]\d{0,9}(\.\d{1,3})|180)$/

  • [4-8][0-9] : Parse Into Range 40 – 89
  • [4-8][0-9]\d{0,9}(\.\d{1,3}) : Parse Into Range 40.00 – 89.00
  • 9[0-9] : Parse Into Range- 90 – 99
  • 9[0-9]\d{0,9}(\.\d{1,3}) : Parse Into Range- 90.00 – 99.00 with three decimal places
  • 1[0-7][0-9] : Parse Into Range- 100 – 179
  • 1[0-7][0-9]\d{0,9}(\.\d{1,3} : Parse Into Range- 90.00 – 99.00 with three decimal places
  • 180 : Parse Into Range – 180-180
Pankaj Singh Sugara

Author Pankaj Singh Sugara

Experienced Software Engineer with a demonstrated history of working in the marketing and advertising industry. Skilled in SQL, Web Applications, PHP, WordPress, and Joomla. Strong engineering professional with a B-TECH focused in Information Technology from JCDM College of Engineering Sirsa, Haryana.

More posts by Pankaj Singh Sugara