How to limit the decimal point in a regex?

by elise_daugherty , in category: Third Party Scripts , 4 months ago

How to limit the decimal point in a regex?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cortez.connelly , 4 months ago

@elise_daugherty 

To limit the decimal point in a regex, you can use the following pattern:


d+.d{1,2}


This pattern will allow for one or two decimal places after the decimal point. Here's an explanation of the pattern:

  • d+: Match one or more digits before the decimal point.
  • .: Match a decimal point.
  • d{1,2}: Match one or two digits after the decimal point.


You can adjust the {1,2} part of the pattern to match a different number of decimal places if needed.

Related Threads:

How to limit input number using regex?
How to limit list of string is pattern with regex?
How to set max limit for each word in the sentence using regex in java?
How to limit size of radius with d3.js?
How to add a point to chart.js line chart?
How to find if point is inside polygon in d3.js?