using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebApplication2.Models
{
    public class NoSwearWords : ValidationAttribute, IClientValidatable
    {
        protected override ValidationResult IsValid(object value,
           ValidationContext validationContext)
        {
            string val = value as string ?? "";

            bool valid = !new string[] { "Pus**", "F**k" }
                .Any(o => val.Contains(o));

            if (!valid)
                return new ValidationResult(
                    base.FormatErrorMessage(base.ErrorMessage));

            return null;
        }

        // client-side    
        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            var rule = new ModelClientValidationRule();
            rule.ValidationType = "noswearwords";
            rule.ErrorMessage = "شما نمیتوانید در متن خود از کلمات Pus  استفاده کنید ";

            yield return rule;
        } 
    }
}