自定义mvc验证特性,手提式有线电话机号号段老扩大,给自定义一个RegularExpress

public class PhoneExpressionAttribute: RegularExpressionAttribute,
IClientValidatable
{
public PhoneExpressionAttribute()
: base(@”^1[2,3,4,5,6,7,8,9][0-9]{1}[0-9]{8}$”)
{
}
public override string FormatErrorMessage(string name)
{
return
String.Format(CultureInfo.CurrentCulture,”手提式有线电话机号码不许确”,name);
}
public IEnumerable<ModelClientValidationRule>
GetClientValidationRules(ModelMetadata metadata, ControllerContext
context)
{
var name = metadata.GetDisplayName();
var rule = new ModelClientValidationRegexRule(FormatErrorMessage(name),
Pattern);
yield return rule;
}
}

 

 

引用
[PhoneExpression]
public string Mobile { get; set; }

相关文章