Regex for 1 or 2 digits with one optional decimal place
问题 I'm using: http://firstopinion.github.io/formatter.js/index.html to mask inputs. I'm looking at "patterns" option and am having trouble writing the regex expression for 1 or 2 digits with an optional decimal place. Good inputs: 2.5 12.5 .5 1 Bad inputs: .25 123.5 1.55 Thank you for any help! 回答1: ^\d{0,2}(?:\.\d)?$ \d{0,2} = 0-2 digits \.\d = decimal point followed by 1 digit (?: ... )? = optional group ^ and $ anchor it to beginning and end DEMO 来源: https://stackoverflow.com/questions