1. var patrn = /^\d+(\.\d+)?$/; var num = 0.11; if (!patrn.exec(num)){ alert("请您输入数字");return; }2. var patten = /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g; var num = 0.11; if(!patten.test(num)){ alert("请您输入数字");return; }
function chk() { var patrn = /^\d+(\.\d+)?$/; var result = true; $("input[type=text]").each(function () { if (!patrn.exec(this.value)) { alert("请输入正确的数字!"); result = false; } }) return result; }