WST.zhengZhengShuIn = function (className){ var rex = /^[1-9]{1}[0-9]*$/;//正整数 $("."+className).keyup(function(event){ var event = event || window.event; var value = $(this).val(); if(value.length>1){ var flagRex =/^0/; if(flagRex.test(value)){ layer.msg('首个字符不能为0',{time:1500}); $(this).val(''); } } }); $("."+className).keypress(function(event){ var event = event || window.event; if (event.charCode == 46 && event.charCode !== 0 && event.charCode < 48 || event.charCode > 57) { return false; } if (/./.test($(this).val()) && event.charCode === 46) { return false; } if ($(this).val() === "" && event.charCode === 46) { return false; } var tails = ($(this).val()).split(".")[1]; if (tails && tails.length === 2 && event.charCode !== 0) { return false; } }); }