How can I limit the quantity selection button on my inventory page?

Topic summary

Goal: prevent customers from selecting a quantity higher than available stock (example: only 1 item left). When a user attempts to change quantity from 1 to 2, the action should be blocked and an error message shown.

Behavior: the same error message should also appear if the user clicks Add to Cart with a quantity exceeding inventory.

UI requirement: the error message must display in the specific position shown in the provided screenshot (image is central to understanding the desired placement).

Request: guidance on what code changes are needed and where to implement them to enforce quantity limits and validation for both the selector and Add to Cart.

Status: no solution provided yet; the thread remains open with a request for implementation details.

Summarized with AI on February 21. AI used: gpt-5.

In the above example, we have only 1 item left of these in the inventory.
What we are trying to do is, once the customer goes from selecting 1 quantity to 2 quantity; they shouldn’t be able to do that and would rather be shown an error message.
Also if he/she clicks the Add to Cart button, they are shown the same message.

P.S: I need the Error message to be shown in the above position.

Can someone please help where and what code changes do I need to make to do this.?