I have created field as required. I tried some ways to validate input and length it's not working.

my functions is:

function Validate(code){
            if(jQuery('#'+'shipping_form_'+code).length != 0){
               /* if(jQuery(this).find('.required-entry').length < 11){
                    alert('Account Number should be 6 digits')

How to validate length & input(numbers only)?



You could use the built in Magento form validation and use either the validate-phoneStrict or validate-phoneLax class.

<form name="phone-form" id="phone-form" method="post">
    <label for="firstname">
        <?php echo $this->__('Phone number') ?> <span>*</span>
    <input  id="firstname" name="firstname" class="input-text  required-entry"/>

<script type="text/javascript">
    var phoneForm = new VarienForm('phone-form');

If you then need to manually call the validation function in some other javascript you can simply do

var validator = new Validation($('phone-form'));
if(validate.validate()) {

See more here: http://blog.magestore.com/2010/04/09/magento-form-validation/

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.