First steps – Defining our rules

The Aurelia validation plugin is based on standard rules. We need to define our own set of rules using the ValidationRules class. This class has some static methods that receive our values and verify that the input value meet our requirements. Also, one validation rule must have one predefined format. The first method we will explain is ensure():

 ValidationRules.ensure('myValidatedProperty')

This method accepts one argument that will be our property name that we want to validate. Also, in case you were validating an object, you are allowed to pass anonymous functions as a parameter:

 ValidationRules.ensure(u => u.firstName)

The second method we will explain is displayName(). This is not required but is useful ...

Get Hands-On Full Stack Web Development with Aurelia now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.