验证工资输入jQuery [英] Validate salary input jQuery

查看:77
本文介绍了验证工资输入jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试验证输入值必须像1.400,00和12.000,00。
如果输入具有正确的值,它应该从禁用的其他内容中删除禁用的类。



我试过这样但是没有成功:(

 < input id =ex2class =salarytype =numberplaceholder =1.400,00  -  12.000 ,00name =salaryRange2/> 

< a href =#id =checkSalary1class =btn next disabled>下一步< / a>

$(#ex2)。on(keyup,function(){
var valid = / ^ \d {1,6}(?:\。\\\ { 0,2})?$ / .test(this.value),
val = this.value;

if(valid){
console.log(输入无效 !;;
this.value = val.substring(0,val.length - 1);
$(#checkSalary1)。removeClass(disabled);
}
else {
$(#checkSalary1)。addClass(disabled);
}
});

任何人都可以帮助如何达到这个条件?



提前致谢

解决方案

你的正则表达式已经解决了,这样的事情会让你更接近:


^ \d {1,2 }。\ n {3},\d {2} $


寻找:




  • 1-2位数

  • 文字

  • 3位数

  • 文字

  • 2位数



您可能希望增强此项以使小数部分可选。



从那里,您需要实际将字符串解析为一个数字,以检查它是否在有效的数值范围内(例如, 95.000,00 将传递正则表达式检查,但不在范围检查中。


I'm trying to validate input value must be like 1.400,00 and 12.000,00. If input has the correct value, it should remove the disabled class from the else stays disabled.

I tried like this but did't get success :(

<input id="ex2" class="salary" type="number" placeholder="1.400,00 - 12.000,00" name="salaryRange2"/>

<a href="#" id="checkSalary1" class="btn next disabled">Next Step</a>

$("#ex2").on("keyup", function(){
    var valid = /^\d{1,6}(?:\.\d{0,2})?$/.test(this.value),
        val = this.value;

    if(valid){
        console.log("Invalid input!");
        this.value = val.substring(0, val.length - 1);
        $("#checkSalary1").removeClass("disabled");
    }
    else{
        $("#checkSalary1").addClass("disabled");
    }
});

Can anyone help how can achieve this condition?

Thanks in advance

解决方案

Your regex is way out, something like this gets you a little closer:

^\d{1,2}.\d{3},\d{2}$

Which looks for:

  • 1-2 digits
  • a literal .
  • 3 digits
  • a literal ,
  • 2 digits

You may like to enhance this to make the decimal portion optional.

From there, you need to actually parse the string to a number to check it is within the valid numerical range (as, for example 95.000,00 would pass on a regex check, but not in the range check.

这篇关于验证工资输入jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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