Form Validation – Input Value Must Contain Number Higher Than 5

contact-formcontact-usform-validationinput

In my contactform I want to display a inputfield, that may only contain a number, higher than 5.

How can I achieve that?

My current code is:

        <li>
            <div class="field">
            <label for="gewensteaantal" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Requested qty') ?></label>
            <div class="input-box">
                <input name="gewensteaantal" id="gewensteaantal" title="<?php echo Mage::helper('contacts')->__('Requested qty') ?>" value="" class="input-text required-entry" type="text" />
            </div>
            </div>
        </li>

Best Answer

You can use custom validation class 'validate-value-greater-than-5' and add following script in form javascript.

Validation.add('validate-value-greater-than-5', 'Please enter a value greater than 5.', function(v) {
    return Validation.get('IsEmpty').test(v) || (v > 5);
});
Related Topic