0

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){
                jQuery('#'+'shipping_form_'+code).show();
                jQuery(this).find('.required-entry').attr('disabled','false');
               /* if(jQuery(this).find('.required-entry').length < 11){
                    alert('Account Number should be 6 digits')
                */}
            }
        }

How to validate length & input(numbers only)?

Thanks.

1

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>
    </label>
    <input  id="firstname" name="firstname" class="input-text  required-entry"/>
</form>

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

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()) {
    alert('validated');
}

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.