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.
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.