Eusthace Eusthace - 1 year ago 655
TypeScript Question

How to validate white spaces/empty spaces? [Angular 2]

I would like to avoid white spaces/empty spaces in my angular 2 form?
Is it possible?
How can this be done?

Answer Source

Maybe this article can help you

In this approach, you have to use FormControl then watch for value changes and then apply your mask to the value. An example should be:

form: FormGroup;

            .map((value) => {
                // Here you can manipulate your value
                value.firstName = value.firstName.trim();
                return value;
            .filter((value) => this.form.valid)
            .subscribe((value) => {
               console.log("Model Driven Form valid value: vm = ",JSON.stringify(value));

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download