gpt4 book ai didi

javascript - Livecycle RegExp - 小数的问题

转载 作者:行者123 更新时间:2023-12-03 10:58:01 25 4
gpt4 key购买 nike

在 Livecycle 中,我验证输入的数字是否为 0 到 10,并且允许一刻钟。借助这个post ,我写了以下内容。

if (!xfa.event.newText.match(/^(([10]))$|^((([0-9]))$|^((([0-9]))\.?((25)|(50)|(5)|(75)|(0)|(00))))$/))
{
xfa.event.change = "";
};

问题是不接受经期。我尝试将 \. 括在括号中,但这也不起作用。该字段是一个文本字段,没有特殊的格式以及更改事件中的代码。

最佳答案

哎呀,这是一个复杂的正则表达式。这可以简化很多:

/^(?:10|[0-9](?:\.(?:[27]?5)?0*)?)$/

说明:

^             # Start of string
(?: # Start of group:
10 # Either match 10
| # or
[0-9] # Match 0-9
(?: # optionally followed by this group:
\. # a dot
(?:[27]?5)? # either 25, 75 or 5 (also optional)
0* # followed by optional zeroes
)? # As said before, make the group optional
) # End of outer group
$ # End of string

测试一下 live on regex101.com .

关于javascript - Livecycle RegExp - 小数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28195451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com