VAlidator起不了作用?
public partial class Demo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ValidatorDemo vd = new ValidatorDemo();
vd.fileName = "dkdfs@33 ";
Response.Write(vd.fileName);
}
}
public class ValidatorDemo
{
private string _fileName = string.Empty;
[StringValidator(InvalidCharacters = "~!$@#%^&* ", MinLength = 3, MaxLength = 8)]
public string fileName
{
get
{
return (string)_fileName;
}
set
{
try
{
_fileName = value;
}
catch (ArgumentException ex)
{
Console.WriteLine(ex.Message.ToString());
}
}
}
}
按我的想法,filename有@应该是不能通过的
可是程序没出错啊
这是为什么?
------解决方案--------------------只在自定义配置节的属性中才这么用过,一般对象没用过这个属性