问题
How will the temperature validation in regex be ? The temperature could be both integer and decimal but not text. I am not setting any limits of how many digits, simple as it could be both integer and decimal.
This is the regex for XX,XX format:
'regex:/[\d]{2},[\d]{2}/'
回答1:
You could do this, it matches XX and XX,XX for any number of digits on either side of ','
:
'regex:/[\d]*,?[\d]*/'
Optionally, you can do this for the units as well: (132.0 C) or (32.0000 F) or (32. K)
'regex:/[\d]*,?[\d]* [CFK]/'
来源:https://stackoverflow.com/questions/22730817/regex-temperature-validation