我需要在模型中动态设置RegularExpression。
我的意思是,我已经将RegularExpression存储在表中,然后我将该值存储在一个变量中。
现在,我想在常规Express验证中提供该变量。
i.e
[RegularExpression(VariableValue, ErrorMessage = "Valid Phone is required")]就像这样
i.e
string CustomExpress = "@"^(\+|\d)(?:\+?1[-. ]?)?\(?([0-9]{2})\)?[-. ]?([0-9]{1})[-. ]?([0-9]{9})$" (from Database's table)
[RegularExpression(CustomExpress, ErrorMessage = "Valid Phone is required")]
public string Phone { get; set; }发布于 2014-03-05 21:30:48
正如Murali所述,数据注释属性值必须是编译时常量。
如果你想执行基于其他模型值的动态验证,你可以尝试使用某种第三方框架(例如,Fluent Validation,甚至can be integrated in ASP.NET's model validation )。
https://stackoverflow.com/questions/22198404
复制相似问题