通过jquery过滤价格输入

时间:2015-10-29 12:57:53

标签: javascript jquery ajax preg-match

我有一个表格,其中用户输入价格,我无法验证价格在这里是下面的代码

 <input placeholder="e.g 22,000" type="text" id="salary" name="salary">
 jQuery("#salary").validate({
     expression: "if (VAL.match(/^[0-9,]{3,10}$/)) return true; else return 
     false;", 
     message: "Please enter Correct Salary"

 });

现在每当用户输入15000时,它应该自动输入这样的“15,000”逗号,如果他输入10万,那么就像这样1,50,000

2 个答案:

答案 0 :(得分:0)

最好将HTML5输入元素与其模式一起使用(您可以为旧版浏览器导入库),也请检查以下链接:HTML 5 Currency format

答案 1 :(得分:0)

可能的重复问题,如果有用,请检查以下链接 - Displaying a number in Indian format using Javascript