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>

Thursday 6 August 2015

How to write mobile number length validation in magento by prototype

<input type="text" id="mobile" name="mobile" title="Mobile" class="input-text required-entry validate-length maximum-length-10 minimum-length-10 validate-digits">

how to get parent Category Id by sub category - Magento

echo $cat_idd = $this->getCurrentCategory()->getParentCategory()->getId();

=============================================
$pre_cat        =       Mage::getModel('catalog/category')->load($catarry[0]);
       
        $cat_idd   = $pre_cat->getParentCategory()->getId();