快速浏览Silverlight3 Beta: 数据检验
2009-04-02 12:01:45 来源:WEB开发网然后就是相应的校验信息类,本示例使用Email校验,相应的CS代码:
public class EmailInfo
{
string address;
string title;
string body;
int format;
public EmailInfo(string address, string title, string body, int format)
{
this.address = address;
this.title = title;
this.body = body;
this.format = format;
}
public string Address
{
get { return address; }
set
{
CheckFieldLength(value, 1, 100);
if (!System.Text.RegularExpressions.Regex.IsMatch(value, @"^[w.]+@[A-Za-z0-9-_]+[.][A-Za-z0-9-_]"))
throw new Exception("邮件格式无效!");
address = value;
}
}
public string Title
{
get { return title; }
set
{
CheckFieldLength(value, 1, 100);
title = value;
}
}
void CheckFieldLength(string value, int min, int max)
{
if ((value.Length < min) || (value.Length > max))
throw new Exception("内容长度应在: " + min + " 至 " + max);
}
public string Body
{
get { return body; }
set
{
CheckFieldLength(value, 1, 100);
body = value;
}
}
public int Format
{
get { return format; }
set
{
if (value == 0)
throw new Exception("请选择相应的邮件格式!");
format = value;
}
}
}
Tags:快速 浏览 Silverlight
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接