How to validate qty increment by product in magento 2?

Products Management in Magento has some advanced inventory feature that supports the qty increment feature or minimum qty allowed in the shopping cart.

For the Enabled Qty Increments feature, the user can only purchase a specific item in multiple of the qty defined in the back panel of the Magento.

You can validate the qty increment for the item by product id, user-specified qty, and optional website id.

Let’s take an example, We have enabled the Qty increment feature for the Product called, Bag. This product has enabled the feature
Qty Increment and added value as 5. User can now purchase only in multiples of 5 otherwise its display error like,

If the user enter qty let’s say 7, an error message is displaying like,
You can buy this product only in quantities of 5 at a time.

You can validate the given qty is valid or not by the coding snippet,

Here Valid Qty Increment value will be in multiples of 5.

In the code snippet, qty is 7, and its not a multiple of 5, hence it will be display errors in the response of the above function,

If you add a valid qty for the item, it will be displayed an empty array.