求一正则表达试
<asp:textbox id= "txt_yy " Runat= "server "> </asp:textbox> <asp:requiredfieldvalidator id= "RequiredFieldValidator2 " runat= "server " ErrorMessage= "* " ControlToValidate= "txt_yy "> </asp:requiredfieldvalidator> <asp:regularexpressionvalidator id= "RegularExpressionValidator2 " runat= "server " ErrorMessage= "两位小数 " ValidationExpression= "^(|[+-]?(0|([1-9]\d*)|((0|([1-9]\d*))?\.\d{1,2})){1,1})$ "
ControlToValidate= "txt_yy "> </asp:regularexpressionvalidator>
必须输入为1.00-150.99之间的数字,不能有任何符号,可以有小数点,请告诉赐教
------解决方案--------------------//验证浮点数
function Fit_Floats(s)
{
var patrn = /^-?([1-9]\d*\.\d+|0|0\.\d+)$/;
if(!patrn.exec(s)) return false;
return true;
}
//验证浮点数范围
//min:最小值
//max:最大值
function Fit_Float(s,min,max)
{
if(min == null || max == null)
return Fit_Floats(s);
else if(min != null && max != null)
{
if(max < min) return false;
if(!Fit_Floats(s)) return false;
if(s < min || s > max) return false;
return true;
}
else
return false;
}