How to Restrict Length of Line Renderer

Im able to drag with the mouse in the scene and create an object with a line renderer, but I want to restrict the max length of the line.
I tried with LineRenderer.bounds.size.y, but I can only detect when it exceeds the limit and cannot set it to the value I want.

If it hits that limit then stop allowing the mouse to draw it.