WEB开发网
开发学院图形图像Flash 快速浏览Silverlight3 Beta: 数据检验 阅读

快速浏览Silverlight3 Beta: 数据检验

 2009-04-02 12:01:45 来源:WEB开发网   
核心提示: 然后就是相应的校验信息类,本示例使用Email校验,快速浏览Silverlight3 Beta: 数据检验(2),相应的CS代码:publicclassEmailInfo{stringaddress;stringtitle;stringbody;intformat;publicEmail

然后就是相应的校验信息类,本示例使用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

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接