How would I verify a email-address (just the format) on the change-handler of an textfield?
Yes, I know how to use this in a form, when the user clicks on a submit-button.
But how would I trigger the validator on a change-eventhandler?
What I want to do is a textbox in which the user can write an email-address, as soon as the string in the textbox validates I want to enable some button. The validator should check the string on every change.
I saw some really cool inputfields here which I want to combine with that function:
https://www.primefaces.org/primeng/#/inputgroup
But I'm not sure if I can use these out of the box.
You can create custom validation function in your page:
import { Component, Injector } from '@angular/core';
import { AddOrderGenerated } from './add-order-generated.component';
@Component({
selector: 'page-add-order',
templateUrl: './add-order.component.html'
})
export class AddOrderComponent extends AddOrderGenerated {
constructor(injector: Injector) {
super(injector);
}
validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
}
and use the function when needed:
1 Like