In MVC validation is easy done using data anotations

Decorate you're property's of the model with data-annotations like this and the inserted value will be validated agains these anotations.

Example

/// 
/// Model class for Contact
/// 
public class ContactViewModel
{
     
    [Required(ErrorMessage="Naam is verplicht")]
    [StringLength(50, MinimumLength = 2, ErrorMessage="Als naam dient u meerdere karakters in te vullen")]
    [Display(Name = "Naam:")]
    public String Naam{get;set;}

Next to the available data-annotations you can build your own validaton with u custom validation class wich, like this:

/// 
/// Name Validation Class
///
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] 
public class NameValidationAttribute : ValidationAttribute
{
    private List NotAcceptedNames = new List(){"Fucker","Shit","..",};
    public NameValidationAttribute (): base("Deze naam wordt niet geaccepteerd")
    {
    }
    public override bool IsValid(object value)
    {
        string naam = (string)value;
        if (NotAcceptetNames.Contains(naam))
            return false;
        return true;
    }      
}

Now it's possible to decorate the name property in the Contact class with the new name validation class:

/// 
/// Model class for Contact
/// 
public class ContactViewModel
{
     
    [Required(ErrorMessage="Naam is verplicht")]
    [StringLength(50, MinimumLength = 2, ErrorMessage="Als naam dient u meerdere karakters in te vullen")]
    [Display(Name = "Naam:")]
    [NameValidationAttribute] 
    public String Naam{get;set;}

Before validation will work on the client side check the modelstate in the controller-action:

/// 
public ActionResult Create(Contact contact)
        {
            if (ModelState.IsValid)
            {
              // Creating the contact
            }
            else
            {
                return View();
            }
        }

{{opmerking.Naam}}:

{{opmerking.OpmerkingText}}

            

Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!