屏蔽的输入插件和正则表达式(用于十进制数字) [英] Masked Input Plugin and regular expressions (for decimal numbers)

查看:77
本文介绍了屏蔽的输入插件和正则表达式(用于十进制数字)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本输入字段,我只想在其中插入数字,然后是逗号,然后再插入两个十进制数字.

I have a text input field in which I want to insert just numbers, then a comma, and then just two decimal digits.

我正在尝试使用屏蔽输入插件通过jQuery获得此信息,但这似乎行不通.

I'm trying to obtain this via jQuery, using Masked Input Plugin, but it seems not to work.

这就是我所拥有的:

<input type="text" name="cash" id="number"/>

<script type="text/javascript">
$.mask.definitions['p']='[0-9]+';
$.mask.definitions['d']='[0-9]{2}';
$("#number").mask("p,d");
<script>

但是结果是一个只有一个数字的掩码,然后是一个逗号,然后是我无法写的东西(它不是数字,也不是字符)

But the result is a mask with just one digit, then a comma, and then something I'm not able to write (it's not a digit, neither a character)

_,_

该插件如何使用正则表达式?

How can I use regular expression with this plugin?

推荐答案

我建议您使用 jquery.maskMoney -这很容易实现:

<input type="text" id="cash"/>

<script src="jquery.maskMoney.js"></script>
<script>
    $("#cash").maskMoney("mask");
</script>

这篇关于屏蔽的输入插件和正则表达式(用于十进制数字)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆