# Field validations

You can easily enable validation for the field values by using the attributes provided.\
Sitefinity CMS supports the following attributes:

* `EmailAddress`\
  Validates an email address.
* `MaxLength`\
  Specifies the maximum length of array or string data that is allowed.
* `MinLength`\
  Specifies the minimum length of array or string data that is allowed.
* `Range`\
  Specifies the numeric range limits for the value of a data field.
* `RegularExpression`\
  Specifies that a data field value in ASP.NET Dynamic Data must match the specified regular expression.
* `Required`\
  Specifies that a data field value is required.
* `StringLength`\
  Specifies the minimum and maximum length of characters that are allowed in a data field.
* `Url`\
  Provides URL validation.

To apply validation attributes, use the following code sample:

```C#
using System.ComponentModel.DataAnnotations;

namespace SitefinityWebApp
{
   public class DemoValidations
   {
       [Url(ErrorMessage = "Enter valid URL.")]
       public string UrlField { get; set; }

       [EmailAddress(ErrorMessage = "Enter valid email.")]
       public string EmailField { get; set; }

       [Range(1, 20, ErrorMessage = "Стойност между {1} и {2}.")]
       public double DoubleValidation { get; set; }
      
       [StringLength(6, ErrorMessage = "Value should be between {1} and {2} symbols.", MinimumLength = 2)]
       public string StringLengthValidation { get; set; }

       [MinLength(2, ErrorMessage = "The message length must be at least {1} symbols.")]
       [MaxLength(10, ErrorMessage = "The message must be less than {1} symbols.")]
       public string StringValidation { get; set; }

       [Required(ErrorMessage = "This is required string {link}.")]
       public string StringFieldRequired { get; set; }
   }
}
```

These validation attributes are provided in Microsoft's ASP.NET [System.ComponentModel.DataAnnotations Namespace](https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations?view=netframework-4.8).
