ASP.NET运行时验证程序 [英] ASP.NET Runtime Validators
本文介绍了ASP.NET运行时验证程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何启动验证器来检查asp.net中的内容?我想要一个正则表达式验证器来验证文本更改的内容
解决方案
尝试以下方法,
在运行时添加ASP.NET验证 [ ^ ]
http://stackoverflow.com/questions/9297822/setting-regularexpressionvalidator-validationexpression-at-runtime [< a href =http://stackoverflow.com/questions/9297822/setting-regularexpressionvalidator-validationexpression-at-runtimetarget =_ blanktitle =New Window> ^ ]
如果以上不起作用,请试试bel ow
1.添加using语句以引用System.Text.RegularExpressions命名空间。
2在textchange事件中添加以下代码,
正则表达式reg =新正则表达式(@^ [a-zA-Z''。 ] {1,40}
);
Response.Write(reg.IsMatch(txtName.Text));
//静态方法:
if(!Regex.IsMatch(txtName.Text,
@^ [a-zA-Z''。] {1,40}
))
{
//名称与架构
不匹配}
How can I initiate a validator to check content in asp.net??I want a regular expression validator to to validate content on text change
解决方案
Hi,
Try the following,
Adding ASP.NET validation at runtime[^]
http://stackoverflow.com/questions/9297822/setting-regularexpressionvalidator-validationexpression-at-runtime[^]
If the above is not working, try the below
1. Add a using statement to reference the System.Text.RegularExpressions namespace.
2. Add the following code in your textchange event,
Regex reg = new Regex(@"^[a-zA-Z''.]{1,40}
"); Response.Write(reg.IsMatch(txtName.Text)); // Static method: if (!Regex.IsMatch(txtName.Text, @"^[a-zA-Z''.]{1,40}
")) { // Name does not match schema }
这篇关于ASP.NET运行时验证程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文