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"> //<{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; } } ] ]) }; 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; ?> //]]> </script>
0 Comments