Monday, 17 August 2015

Phone number validation

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

  
    Validation.add('validate-mobile','<?php echo Mage::helper('contacts')->__('Please enter your mobile number.'); ?>',function (v, elm) {
          
        var reMax = new RegExp(/^maximum-length-[0-9]+$/);
        var reMin = new RegExp(/^minimum-length-[0-9]+$/);
      
        var result = true;
      
        if(Validation.get('IsEmpty').test(v))
        {
           result =false;
        }
      
      
        $w(elm.className).each(function(name, index) {
            if (name.match(reMax) && result) {
               var length = name.split('-')[2];
               result = (v.length <= length);
            }
            if (name.match(reMin) && result && !Validation.get('IsEmpty').test(v)) {
                var length = name.split('-')[2];
                result = (v.length >= length);
            }
          
        });
        return result;
    });
  
  
    var contactForm = new VarienForm('mobile_appForm',false);
  
  
  
 
//]]>
jQuery(document).ready(function(){
    var contactForm = new VarienForm('mobile_appForm',false);
    jQuery("#mobileappbuttom").click(function(e){
            if(contactForm.validator && contactForm.validator.validate()){
                e.preventDefault();
                var base_url=jQuery.trim(jQuery("#base_url").val());
                var mobile_number=jQuery("#mobile_number").val();
                jQuery.ajax({
                    url: base_url+'contacts/index/mobileapp/',
                    type:        'post',
                    data:({'mobile_number':mobile_number}),
                    success: function(msg){
                       jQuery("#aleart-text").text(msg);
                       //jQuery("#aleart-texterror").hide();
                        Effect.Appear('aleart-text', { duration: 0.2, delay: 1 });
                    }
                });
              
            }else {
                jQuery("#aleart-text").css({"display":"none"});
              //  jQuery("#aleart-texterror").text("Please enter your mobile number.");
            }
          
          
        });
  
    });
</script>

No comments:

Post a Comment