2
Reply

How to apply two validation on condition base in MVC 4 ?

Mangesh barmate

Mangesh barmate

Nov 23 2015 1:18 AM
344

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.


Answers (2)