i want the validation like, I have text box and i want to validate the postal code for the country where the site being open. like if i open the site in U.k then when i write postal code in textbox the textbox should validate only U.K postal code using fluent validation.i have try some code here but its not working.
in validator class file
public Ekhati_AdminUser_Mst_Validator()
{
RuleFor(x => x.Postcode).NotEmpty().Must(IsValidCountryCategory).WithMessage("Select a valid country");
}
public bool IsValidCountryCategory(Ekhati_AdminUser_Mst customer, string homeCountry)
{
homeCountry = "^(([0-9]{5})*-([0-9]{4}))|([0-9]{5})$";
var ValidCountries = new List<string>();
//categorias v�lidas para clientes do tipo R
ValidCountries.Add("^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$");
return ValidCountries.Contains(homeCountry);
}
and in cshtml page
@Html.ValidationMessageFor(model=>model.Postcode, String.Empty, new { @style = "color:red;!important" })
here i try this static entry only for testing.