I have added a qty box with add to cart button on product list page like

<input type="number" min="1" name="qty" maxlength="12" value="1" title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty" data-validate="{'required-number':true,digits:true,'validate-greater-than-zero':true}"/>

How I can validate this?

1 Answer 1

    require(["jquery"], function ($) {
        $(document).ready(function () {
            $('.tocart').click(function () {
                $Obj = $(this).closest('form');
                if ($Obj.valid()) {
                } else {
                    return false;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.