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