Tuesday, January 15, 2013

Magento: Mobile number validation using custom class

HTML code

<input type="text" name="telephone" id="telephone" value="<?php echo $this->htmlEscape($this->getFormData()->getTelephone()) ?>" title="<?php echo $this->__('Telephone') ?>" class="input-text validate-custommobile" />



Js code

<script type="text/javascript">
    //<![CDATA[

if(Validation) {
        Validation.addAllThese([
        ['validate-custommobile','Enter correct mobile number',
        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 !=10){
            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;
        }

        }
        ]])};
        var dataForm = new VarienForm('form-id', true);

//]]>

</script>  

1 comment:

  1. i am using your code and am getting error,, how can i use properly,


    your code : http://pasted.co/17e7a339

    ReplyDelete