i am designing my form on xlsx, in a certain field i want to collect decimal input with limit of exactly 1 decimal place. the decimal place should range from 0-9. i have earlier used regex(., ‘^\d+.\d{1,}$’) but it only accepts the decimal places from 1-9 rejecting zero(0). kindly help
Welcome back to the community, @oscarthoya! So you mean you wish to have a regex code that supports a single-digit decimal including a zero?
Thanks for your reply @Kal_Lam , thats what i intend to have, any suggestions on the wright formula to use.
Try this regular expression:
^\d+\.\d$
You can test it here: https://regex101.com/
You had a couple ‘bugs’ in your original regex: first, \d{1.}
would repeat the decimal place multiple times, so 1.23456
would have been accepted. Also, you have to escape the decimal point (with \.
) because the period char .
has a special meaning in regex’s.
Note, this regex requires a leading number before the decimal point, so .5
will be rejected; you’ll have to enter 0.5
instead. Your above description wasn’t prescriptive on this.