The front end A regular that preserves n decimal places February 5, 2024 by Renee Koshy No Comments Regex with n decimal places: const FloatReg = ( n ) = > { // Keep n decimal places const str = ` ^ ((0 \ \ [0-9] {1,${n}})|([1-9]\\d*(\\.[0-9]{1,${n}})? ) $`; return new RegExp( str ); } Copy the code