Limit number of lines in field type input


i there a easy way to limit the number of possible lines to i.e. 4 lines in a field type input. Rows paramter is only for gui but I need to limit the number of line in the field. And this should contain long text and also line breaks.

I can count i.e. in onInputChange the number of typed character and stop input after i.e. 1024. But then it´s possible to add 5 line breaks and this is more than the 4 as maximum.

I can also count number of characters and number of line breaks and try to calculate is this more than 4 lines but this is not a smart way.

Why I want to do so. I create from the form later a PDF and on this the number of lines should be limited otherwise I create unwanted page breaks.

Unfortunately, there is no a ready-to use functionality which can fulfill your task.
Retrieving the content of input, breaking it in lines and checking length of each line is the only possible solution, as far as I can see.