title: VAT validation from php to javascript
body: <p>I have fine this interesting function at this <a href="https://stackoverflow.com/a/29955950/9358981">link</a>
  This work well for check the VAT number in EU. But I can't integrate with my registration form. I will like to transform this in a js function, to use this before I send the registration data, I'm trying but I can't do it, can same one help me? </p>
  
  <p>The code is this in the link</p>
  
  <pre><code>function viesCheckVAT($countryCode, $vatNumber, $timeout = 30) {
      $response = array ();
      $pattern = '/&lt;(%s).*?&gt;([\s\S]*)&lt;\/\1/';
      $keys = array (
          'countryCode',
          'vatNumber',
          'requestDate',
          'valid',
          'name',
          'address'
         );
  
      $content = "&lt;s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'&gt;
          &lt;s11:Body&gt;
           &lt;tns1:checkVat xmlns:tns1='urn:ec.europa.eu:taxud:vies:services:checkVat:types'&gt;                                        
           &lt;tns1:countryCode&gt;%s&lt;/tns1:countryCode&gt;
           &lt;tns1:vatNumber&gt;%s&lt;/tns1:vatNumber&gt;
           &lt;/tns1:checkVat&gt;
          &lt;/s11:Body&gt;
        &lt;/s11:Envelope&gt;";
  
      $opts = array (
          'http' =&gt; array (
          'method' =&gt; 'POST',
          'header' =&gt; "Content-Type: text/xml; charset=utf-8; SOAPAction: checkVatService",
          'content' =&gt; sprintf ( $content, $countryCode, $vatNumber ),
          'timeout' =&gt; $timeout
          )
         );
  
      $ctx = stream_context_create ( $opts );
      $result = file_get_contents ( 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService', false, $ctx );
  
      if (preg_match ( sprintf ( $pattern, 'checkVatResponse' ), $result, $matches )) {
        foreach ( $keys as $key )
        preg_match ( sprintf ( $pattern, $key ), $matches [2], $value ) &amp;&amp; $response [$key] = $value [2];
      }
     return $response;
    }
  
     $arr = viesCheckVAT($countryCode, $vatNumber);
  
     if ($arr[valid] == fasle) {
      ...
      } else {
      ...
      }
  </code></pre>
  
  <p>Now I really like to use this servis true Javasscript. In the way I can check the number before sending data via PHP.</p>
  
  <p>How I can write this function in JS?
  For the array there are not problem, but can I make the SOAP call?  </p>