[Fixed] Create a generic validator to prevent newline characters getting added during paste of data in text area + Angular 8

Issue

I would like to create a custom validator that would be able to detect and remove any newline at the end of the text in text fields, without being implicitly called on those components.

It would be able to detect any text fields and automatically implement the validator logic when the page loads.

I know I can simply validate each individual text field but it numbers in 100s and hence would like to know an elegant approach.

Solution

I was able to achieve this by two methods:
One by having an interceptor and second by having a custom directive for some specific fields which on blur i.e., when the mouse moves away from a field trims the data

Leave a Reply

(*) Required, Your email will not be published