[Solved] Regex for decimal number [closed]


You can use this regex

^(?=\d)(?!0(?![.]))(?:\d{0,3})(?:[.]\d{1,3})?$

Regex Demo

Regex Breakdown

^ #Start of string
 (?=\d) #Lookahead to ensure there is a dot or number
 (?!0(?![.])) #Negative lookahead to ensure there is no 0 in starting followed by .
 (?:\d{0,3}) #Match at most three digits before decimal
 (?:[.]\d{1,3})? #Match at most three digits after decimal. If there is a dot there should be at least one digit after dot
$ #End of string

2

solved Regex for decimal number [closed]