In billing.phtml file Zip/Postal Code validation is not working properly.

1) When I field is empty it's asking it's required fine.

2) But letter's also allowing this field. I don't want to allow letters only Numeric values will allow.

my code is

<div class="field">
                        <label for="billing:postcode" class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
                        <div class="input-box">
                            <input type="text" title="<?php echo $this->__('Zip/Postal Code') ?>" name="billing[postcode]" id="billing:postcode" value="<?php echo $this->escapeHtml($this->getAddress()->getPostcode()) ?>" class="input-text validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" />


I set to true in javascript also

var billingForm = new VarienForm('co-billing-form',true);

May I know Where I went wrong? or how to do this?


1 Answer 1


You should be able to change the class from "validate-zip-international" to "validate-number" to add Magento's frontend JS validation for numbers, or "validate-digits".

Source: /js/prototype/validation.js for a list of all validation classes (addAllThese method)

['validate-number', 'Please enter a valid number in this field.', function(v) {
    return Validation.get('IsEmpty').test(v) || (!isNaN(parseNumber(v)) && !/^\s+$/.test(parseNumber(v)));
['validate-digits', 'Please use numbers only in this field. Please avoid spaces or other characters such as dots or commas.', function(v) {
     return Validation.get('IsEmpty').test(v) ||  !/[^\d]/.test(v);
  • I have added this code to /js/prototype/validation.js file . and clear the cache as well as js cache also, but not working properly (not asking only numbers... message)
    – Magento007
    Jul 10, 2014 at 11:17
  • Can you post up your new code? Jul 10, 2014 at 12:31
  • I have updated class to "validate-digits", now it's accepting only numbers. thank you.
    – Magento007
    Jul 10, 2014 at 13:23

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.