0

overall country telephone number validation in magento checkout page

i add the regular expression for the telephone number validation.js in js/prototype/validation.js

['validate-phoneStrict',
 'Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.',
 function(v)
 {
     return Validation.get('IsEmpty').test(v)
         || /\(?([0-9]{4})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/.test(v);
 }
],

I need the regular expression for the overall countries ,....please help me

Khaled.K
  • 5,828
  • 1
  • 33
  • 51
Larenz Danny
  • 1
  • 2
  • 6

2 Answers2

1

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-numeric-contact" />

js Code add below in billing.phtml

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

if(Validation) {
        Validation.addAllThese([
        ['validate-numeric-contact','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>  
Pankaj Upadhyay
  • 2,114
  • 21
  • 22
0

Please search on the website for related questions.

What regular expression will match valid international phone numbers? This contains the regex you need.

An example solution for you would be:

[ 'validate-phoneStrict',
  'Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.',
  function(v)
  {
      return Validation.get('IsEmpty').test(v)
          || /\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{1,14}$/.test(v);
  }
]

I used the accepted answer in the above question, without testing it myself. Please also read the last answer on that page for the caveats on this regex

Community
  • 1
  • 1
mvbrakel
  • 936
  • 5
  • 16