Asp.NET 过滤的文本框扩展器 - 无效的字符序列?
是否可以将字符序列放入 Asp.NET 中的 Filtered TextBox Extender 中?我的猜测是否定的,但我很好奇。我希望用户能够输入字符(例如&和#),但不能输入无效序列(例如&#)。
为什么不直接使用正则表达式呢?因为当提交表单时,所有字段都会传递到服务器......包括不属于验证组的字段。这些字段不会被检查,并且可能会触发“潜在危险的 Request.Form 值...”,又名 HttpRequestValidationException。阻止该消息是整个过程的重点。我宁愿使用正则表达式验证器告诉用户,什么他们做错了......但我会解决阻止他们输入错误字符(&#、<、>)的问题:
编辑:有点事后的想法,但如果有更好的方法来防止所有文本框包含在内。人物,那就太好了!
Is it possible to put a character sequence in a Filtered TextBox Extender in Asp.NET? My guess is no, but I'm curious. I want the user to be able to enter the characters (such as & and #), but not enter the invalid sequences (such as ).
Why not just use a regular expression? Because when the form is submitted, all the fields are passed to the server...including fields that are not part of the validation group. These fields do not get checked and may trigger the "A potentially dangerous Request.Form value…”, aka the HttpRequestValidationException. And preventing that message is the whole point of this. I'd rather tell the user, with a regex validator, what they are doing wrong...but I will settle for preventing them from typing the bad chars (, <, >).
Edit: sort of an afterthought, but if there's a better way to prevent ALL TextBoxes from including the characters, that'd be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为所有文本框设置一个 onkeydown 函数,并检查按下的字符,如果无效,则删除最后一个字符。另外,对于您的组合字符串,您只需检查前面的字符是否使其无效,然后将其全部删除。
该类型函数的一个示例是:
You can just have a function onkeydown for all your text boxes and that checks the character pressed and if it's invalid just remove that last character. Also for your combination strings you can just check to see if the previous characters make it invalid then remove all of them.
An example of that type of function is: