Registration Mobile number validation In Magento

Some time in account registration we need validate mobile no,
for that use this 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-mobileno" />

Replace script

 <script type="text/javascript">
//<![CDATA[
 var dataForm = new VarienForm('form-validate', true);
//]]>
</script>

To

 <script type="text/javascript">
//<![CDATA[
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;
}

}
]])};
 var dataForm = new VarienForm('form-validate', true);
//]]>
</script>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s