======================== 字符验证 ========================== 数据库里的字段是double类型,当我在文本框里输入除数字以外的字符时,我要进行在后台验证判断,除数字外添加到数据库用0或者空字符来代替,这方法该如何去写,然后取出来时用一个别的字符替换回来???? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 验证时随便怎么验证都行 方法很多、除数字外添加到数据库用0或者空字符来代替 既然是double 类型难道你还想输入abcd然后全部换成0哇、 string s=TextBox1.Text;s=Regex.Replace(s,"\\D","0"); ^\+?[1-9][0-9]*$然后取出来时用一个别的字符替换回来这个不知道怎么事replace? 就这个,用正则表达式判断然后再replace啊 客户端服务端双验证,必须的!用自定义验证控件很简单就搞掂了<script type="text/javascript">function ValidatorDesposite(source, argument) { argument.IsValid = isNaN($("#<%=txtDesposite.ClientID %>").val())== false;} </script><asp:TextBox ID="txtDesposite" runat="server" Width="60" onkeyup="this.value=this.value.replace(/[^\d\.]/g,'')"></asp:TextBox> <font color="gray">(单位:<b>元</b>)</font> <asp:CustomValidator ID="CustomValidator4" runat="server" ValidateEmptyText="false" ControlToValidate="txtDesposite" ErrorMessage="押金输入错误!" ClientValidationFunction="ValidatorDesposite" OnServerValidate="Price_Validator"></asp:CustomValidator> protected void Price_Validator(object sender, ServerValidateEventArgs e) { decimal price; e.IsValid = decimal.TryParse(txtPrice.Text.Trim(), out price) && price > 0; } 你这其实都没必要验证onblur=javascript:if(!isNaN($("#<%=txtDesposite.ClientID %>").val()))$("#<%=txtDesposite.ClientID %>").val(0);O了 请教如何判断.net控件被选中? 在asp.net中如何编写下面的效果 【门诊划价(\<R)】粘贴到label控件里的text,显示不全,显示为:【门诊划价(\ 如何记录文本域中的换行符 麻烦大家帮我看一下,修改记录问题 怎么动态添加行的同时保持输入的数据 求C#.net整套源码系统! session为什么会丢失呢?怎样保存呢? 如何在服务器端修改panel的Height? 如何叛断sub里的代码完全执行? 数据中是“~”显示的时候是网站的根目录。 想找一个asp.net方向的技术高手合作
除数字外添加到数据库用0或者空字符来代替 既然是double 类型难道你还想输入abcd然后全部换成0哇、
s=Regex.Replace(s,"\\D","0");
然后取出来时用一个别的字符替换回来这个不知道怎么事replace?
<script type="text/javascript">
function ValidatorDesposite(source, argument) { argument.IsValid = isNaN($("#<%=txtDesposite.ClientID %>").val())== false;}
</script>
<asp:TextBox ID="txtDesposite" runat="server" Width="60" onkeyup="this.value=this.value.replace(/[^\d\.]/g,'')"></asp:TextBox> <font color="gray">(单位:<b>元</b>)</font> <asp:CustomValidator ID="CustomValidator4" runat="server" ValidateEmptyText="false" ControlToValidate="txtDesposite" ErrorMessage="押金输入错误!" ClientValidationFunction="ValidatorDesposite" OnServerValidate="Price_Validator"></asp:CustomValidator> protected void Price_Validator(object sender, ServerValidateEventArgs e)
{
decimal price;
e.IsValid = decimal.TryParse(txtPrice.Text.Trim(), out price) && price > 0;
}
onblur=javascript:if(!isNaN($("#<%=txtDesposite.ClientID %>").val()))$("#<%=txtDesposite.ClientID %>").val(0);
O了