简体   繁体   English

HTML.Textbox验证在文本框中输入的字符串

[英]HTML.Textbox validate a string entered in a textbox

Is there a way to validate the information entered in this text box code - 有没有一种方法可以验证在此文本框代码中输入的信息-

@Html.TextBox(string.Format("Customer.CustomerMeasurementProfiles[{0}].CustomerMeasurements[{1}].Value", i, k), oMeasurement.Value, new { @class = "form-control input-sm " })

I want to check if it is blank or null, if so I want to put a 0 in the field. 我想检查它是否为空或为空,如果是的话,我想在该字段中输入0。

You may need a 2 step solution. 您可能需要两步解决方案。 The first one would be handling the onchange event of your text box in client-side JavaScript. 第一个方法是在客户端JavaScript中处理文本框的onchange事件。 It is not bulletproof, as any client-side behavior can be spoofed/overridden. 它不是防弹的,因为任何客户端行为都可以被欺骗/覆盖。 The next step would be checking/setting the submitted value in your controller code. 下一步将是在控制器代码中检查/设置提交的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM