Extend form input fields validation

By default, MVC form fields have both client-side and server-side validation. You can, however, customize the default validation behavior by editing the settings and properties for each field. For example, you can customize the default maximum length value of the text box field that enforces limitations of the text the user enters.

You customize the client-side validation via the HTML5 built-in validation attributes. On the other hand, you customize the server-side validation via the business logic in the field model. You basically override and change the default validation models.

PREREQUISITES: You first need to register a custom module. For more information, see For developers: Install a module with the Fluent API.

In the following example, you override the default validation of the Paragraph text field. You override the client-side validation by changing the ValidationAttributes property value in the following manner:

The code above, you make every Paragraph text field a required field. Note that this change only affects the client-side validation.

To change the server-side validation logic, you override the IsValid method in the following manner:

Thus, every server-side validation of this field is forced to return true. Depending on your requirements, you can add your own custom logic of validating the field.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its 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 .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?