如何在MVC 4的条件库中应用两个验证? [英] How to apply two validation on condition base in MVC 4 ?

查看:59
本文介绍了如何在MVC 4的条件库中应用两个验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi,

I have applied validation and it is working fine.

For ex.

[LocalizedRequired(ResourceName = (ResourceFile.Setting), ResourceKey = ServerSettingResources.Required)]
[LocalizedRegularExpression("[^<>]*$", ResourceName = (ResourceFile.Setting), ResourceKey = ServerSettingResources.IllegalCharacterMessage)]
public string CustomField { get; set; }

It is working fine for illegal character.

This CustomField  used for 2 to 3 views.

I am using boelow code in view-

@Html.TextBoxFor(model => model.CustomField , new { maxlength = "20" })
@Html.ValidationMessageFor(model => model.CustomField, null, new { @id = "ValidationMessage" })

Now,

I want to apply email validation when my scenario for email at this time i want to apply email validation as well, otherwise i want to perform illegal character validation only.

How would i achieve this ?

Thanks.

推荐答案

,ResourceName =(ResourceFile.Setting),ResourceKey = ServerSettingResources.IllegalCharacterMessage)]
public string CustomField { get ; set ;}

工作正常 非法字符。

此CustomField使用 2 3 次。

使用 boelow code in view-

@ Html.TextBoxFor(model = > model.CustomField, new {maxlength = 20 })
@ Html.ValidationMessage对于(model = > model.CustomField, null {@id = ValidationMessage})

现在,

我希望在我的方案 电子邮件时应用电子邮件验证 时间我想将电子邮件验证应用为,否则我只想执行非法字符验证。

如何实现

谢谢。
", ResourceName = (ResourceFile.Setting), ResourceKey = ServerSettingResources.IllegalCharacterMessage)] public string CustomField { get; set; } It is working fine for illegal character. This CustomField used for 2 to 3 views. I am using boelow code in view- @Html.TextBoxFor(model => model.CustomField , new { maxlength = "20" }) @Html.ValidationMessageFor(model => model.CustomField, null, new { @id = "ValidationMessage" }) Now, I want to apply email validation when my scenario for email at this time i want to apply email validation as well, otherwise i want to perform illegal character validation only. How would i achieve this ? Thanks.


这篇关于如何在MVC 4的条件库中应用两个验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆