1

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>
  • higher than 5 digits or higher than 5 ie (6, 7 and so on ) ? – Pradeep Sanku Aug 11 '16 at 7:24
2

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);
});
2

You have to just use type=number in input.

 <input type="number" name="quantity" min="6">

Now user have input 6 or higher than 6 to submit form otherwise display error with no form submit.

0

Use this class :

class="input-text validate-length maximum-length-50 minimum-length-5 validate-greater-than-zero validate-number validate-digits required-entry"

This will accept only digits and numbers with minimum of 5 and maximum of 50 length

These classes "validate-length maximum-length-50 minimum-length-5" are responsilble to handle the max and min length

  • Thanks, but that does not work. The minimum length should be 5. Which is not the number, but the characters. So than a number must be at least a 5 digit number. – JGeer Aug 11 '16 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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