Regex temperature validation

允我心安 提交于 2020-01-16 05:11:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!