1.Open Your form and in the input field add the class : validate-mobileno

For Example:

<input type="text" name="<?php echo $attribute->getAttributeCode(); ?>" id="<?php echo $attribute->getAttributeCode(); ?>" value="<?php echo $this->escapeHtml($fieldValue); ?>" title="<?php echo $this->__($frontEndLabel); ?>" class="input-text validate-mobileno validate-digits <?php echo $fieldRequiredClass; ?> <?php echo $fieldFrontendClass ;?>" />

2. At the bottom of your form you will find a script add the following code in your script tag

if(Validation) {
    Validation.addAllThese([
        ['validate-mobileno','Enter correct mobile number (Eg:919986858483)',
            function(v){
                var timePat ="^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$";
                // var matchArray = v.match(timePat);
                if(v.length > 0){
                    if(v.length !=12){
                        return false;
                    }
                    else if(v[0] != 9 || v[1] != 1 ){
                        return false;
                    }
                    else if(v[2]!=9 && v[2]!=8 && v[2]!=7){
                        return false;
                   }
                    return true;
                }
                else {
                    return false;
                }
            }
        ]
    ])
};

For Example:

<script type="text/javascript">
    //<!&#091;CDATA&#091;
    if(Validation) {
        Validation.addAllThese(&#091;
            &#091;'validate-mobileno','Enter correct mobile number (Eg:919986858483)',
                function(v){
                    var timePat ="^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9&#091;0-9&#093;(\s){0,1}(\-){0,1}(\s){0,1}&#091;1-9&#093;{1}&#091;0-9&#093;{7}$";
                    // var matchArray = v.match(timePat);
                    if(v.length > 0){
                        if(v.length !=12){
                            return false;
                        }
                        else if(v&#091;0&#093; != 9 || v&#091;1&#093; != 1 ){
                            return false;
                        }
                        else if(v&#091;2&#093;!=9 && v&#091;2&#093;!=8 && v&#091;2&#093;!=7){
                            return false;
                       }
                        return true;
                    }
                    else {
                        return false;
                    }
                }
            &#093;
        &#093;)
    };
        var dataForm = new VarienForm('form-validate', true);
        <?php if($this->getShowAddressFields()): ?>
        new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
        <?php endif; ?>
    //&#093;&#093;>
    </script>

working-on-a-computer-smiley-emoticon

Categories: Magento

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *