Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
16825 efrain 1
<!DOCTYPE html>
2
<html>
3
  <head>
4
    <meta charset="utf-8">
5
    <title>Example: Validation</title>
6
    <link rel="stylesheet" href="../css/prism.css">
7
    <link rel="stylesheet" href="../../build/css/intlTelInput.css?1603274336113">
8
    <link rel="stylesheet" href="../../build/css/demo.css?1603274336113">
9
 
10
      <link rel="stylesheet" href="../css/isValidNumber.css?1603274336113">
11
 
12
 
13
    <!-- GOOGLE ANALYTICS -->
14
    <script>
15
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
16
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
17
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
18
      })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
19
      ga('create', 'UA-85394876-1', 'auto');
20
      ga('send', 'pageview');
21
    </script>
22
    <!-- /GOOGLE ANALYTICS -->
23
  </head>
24
 
25
  <body>
26
    <a href="/">Back</a>
27
    <h1>Example: Validation</h1>
28
    <p>Use the isValidNumber method (which utilises Google's libphonenumber) to validate the telephone number on the blur event.</p>
29
 
30
    <h2>Markup</h2>
31
    <pre><code class="language-markup">&lt;input id=&quot;phone&quot; type=&quot;tel&quot;&gt;
32
&lt;span id=&quot;valid-msg&quot; class=&quot;hide&quot;&gt;✓ Valid&lt;/span&gt;
33
&lt;span id=&quot;error-msg&quot; class=&quot;hide&quot;&gt;&lt;/span&gt;
34
</code></pre>
35
 
36
    <h2>Code</h2>
37
    <pre><code class="language-javascript">var input = document.querySelector(&quot;#phone&quot;),
38
  errorMsg = document.querySelector(&quot;#error-msg&quot;),
39
  validMsg = document.querySelector(&quot;#valid-msg&quot;);
40
 
41
// here, the index maps to the error code returned from getValidationError - see readme
42
var errorMap = [&quot;Invalid number&quot;, &quot;Invalid country code&quot;, &quot;Too short&quot;, &quot;Too long&quot;, &quot;Invalid number&quot;];
43
 
44
// initialise plugin
45
var iti = window.intlTelInput(input, {
46
  utilsScript: &quot;../../build/js/utils.js?1603274336113&quot;
47
});
48
 
49
var reset = function() {
50
  input.classList.remove(&quot;error&quot;);
51
  errorMsg.innerHTML = &quot;&quot;;
52
  errorMsg.classList.add(&quot;hide&quot;);
53
  validMsg.classList.add(&quot;hide&quot;);
54
};
55
 
56
// on blur: validate
57
input.addEventListener(&#39;blur&#39;, function() {
58
  reset();
59
  if (input.value.trim()) {
60
    if (iti.isValidNumber()) {
61
      validMsg.classList.remove(&quot;hide&quot;);
62
    } else {
63
      input.classList.add(&quot;error&quot;);
64
      var errorCode = iti.getValidationError();
65
      errorMsg.innerHTML = errorMap[errorCode];
66
      errorMsg.classList.remove(&quot;hide&quot;);
67
    }
68
  }
69
});
70
 
71
// on keyup / change flag: reset
72
input.addEventListener(&#39;change&#39;, reset);
73
input.addEventListener(&#39;keyup&#39;, reset);
74
</code></pre>
75
 
76
    <h2>Result</h2>
77
    <div id="result">
78
      <input id="phone" type="tel">
79
<span id="valid-msg" class="hide">✓ Valid</span>
80
<span id="error-msg" class="hide"></span>
81
 
82
    </div>
83
 
84
    <script src="../js/prism.js"></script>
85
    <script src="../../build/js/intlTelInput.js?1603274336113"></script>
86
    <script src="./js/isValidNumber.js?1603274336113"></script>
87
  </body>
88
</html>