Asp.Mvc 2.0用户登录实例讲解---(4)服务器端验证(9)
}
[DisplayName("确认密码")]
[Required(ErrorMessage="确认密码不能为空!")]
[StringLength(10, ErrorMessage = "确认密码长度不能小于5位",MinimumLength=5)]
public string ConfirPwd
{
get;
set;
}
/// <summary>
/// 用户邮箱
/// </summary>
[DisplayName("邮箱")]
//[DataType(DataType.EmailAddress)]
[RegularExpression(@"^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$", ErrorMessage = "电子邮件格式错误")]
public string Email
{
get;
set;
}
}
/// <summary>
/// 此自定义类用于验证密码和确认密码必须一致
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public class PwdMatch :ValidationAttribute
{
private object _typeid = new object();
public string PWD { get; set; }//密码
public string ConfirmPwd { get; set; }//确认密码
public PwdMatch(string pwd, string confirmPwd)
: base()
{
PWD = pwd;
ConfirmPwd = confirmPwd;
}
/// <summary>
/// 返回错误的提示信息
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
相关新闻>>
- 发表评论
-
- 最新评论 更多>>