gpt4 book ai didi

JavaScript 正则表达式 for Money 非 JQuery

转载 作者:行者123 更新时间:2023-11-28 02:10:20 25 4
gpt4 key购买 nike

我需要一个货币掩码作为输入,问题是我无法在我的应用程序上使用 jquery。

例如,如何使用正则表达式“on key up”来执行此操作?

这是我的代码:

<tr>
<td>
money:
<input type="text" class="money" maxlength="22" id="money" name="money">
</td>
</tr>

我的格式看起来像00.000,00

最佳答案

由于您没有提供格式,因此无法给您直接答案...

在字符串上测试正则表达式的 JavaScript 方法是:

function regexmoney(){
var patt=new RegExp(pattern,modifiers);
var string = document.getElementById('money').value;
var result = patt.test(string);//Returns true/false
if(!result){
var charArray=string.split();
//Iterate through the array and arrange the chars as
//you see fit (returning moneyresult)
document.getElementById('money').value = moneyresult;
}
}

然后是 HTML:

<tr>
<td>
money:
<input type="text" onkeyup="regexmoney()" class="money" maxlength="22" id="money" name="money">
</td>
</tr>

并生成正则表达式 http://txt2re.com/

希望这有帮助...

关于JavaScript 正则表达式 for Money 非 JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17192946/

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