Applying Validation Rules to an Object of a Class


I don’t know how to use Applying Validation Rules to an Object of a Class.
You can see it in below link at section ‘Applying Rules to an Object’.
As there is no html example .
I tried it myself, but it does not work.

Please see below:

import { ValidationControllerFactory, Validator, ValidationRules, validateTrigger, ValidationController } from ‘aurelia-validation’;
import { autoinject } from “aurelia-framework”;
import { bindable, customElement } from “aurelia-templating”;

export class EditTest {
@bindable properties = { name: “”, id: “”};
@bindable canSave: boolean = false;
private validationController: ValidationController;

    private validator: Validator,
    private controllerFactory: ValidationControllerFactory
) {
    this.validationController = controllerFactory.createForCurrentScope(validator);
    this.validationController.validateTrigger = validateTrigger.changeOrBlur;
    this.validationController.subscribe(event => this.validate());

attached() {

        (value) => !/[*<>":?/|\\]/.test(value),
        "Name cannot contain following charactors: \\ / + * & % ?" 


private validate() {
        .then(results => {
            return this.canSave = results.every(result => {
                return result.valid;


And html is here:

label>edit model :</label
input value.bind=“ & validate”
button disabled.bind="!canSave">can save</button

Anyone can help out? With many thanks.



This is how I do validation change-password-dialog.ts Also take a look at the FormValidator module. I manually trigger the validation. I m not aware of the subscriber on the controller itself. Hope it helps =)


I’ll take a look how it works.
In my scenario, I need sync validation on input box, not when user click submit button.
Anyway, thank you.


I resolved this issue as I made a mistake. Change like below.

this.validator.validateObject(this) --------> this.validator.validateObject( )