Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,我有一个正则表达式,它可以帮助我验证用户输入。
它只允许带 2 个小数位的正数,这是我的正则表达式:
^[0-9]+\.[0-9][0-9]$
我希望它也适用于负数。 如何更改正则表达式以允许负值?
如下所示:
^(\-)?[0-9]+\.[0-9][0-9]$
查看工作演示
认为这会起作用:
^(-?)[0-9]+\.[0-9][0-9]$