16825 |
efrain |
1 |
<!DOCTYPE html>
|
|
|
2 |
<html>
|
|
|
3 |
<head>
|
|
|
4 |
<meta charset="utf-8">
|
|
|
5 |
<title>Example: National Mode</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 |
|
|
|
11 |
<!-- GOOGLE ANALYTICS -->
|
|
|
12 |
<script>
|
|
|
13 |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
|
14 |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
|
15 |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
|
16 |
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
|
|
17 |
ga('create', 'UA-85394876-1', 'auto');
|
|
|
18 |
ga('send', 'pageview');
|
|
|
19 |
</script>
|
|
|
20 |
<!-- /GOOGLE ANALYTICS -->
|
|
|
21 |
</head>
|
|
|
22 |
|
|
|
23 |
<body>
|
|
|
24 |
<a href="/">Back</a>
|
|
|
25 |
<h1>Example: National Mode</h1>
|
|
|
26 |
<p>Allow users to enter their national number, and then convert it to international format using the public method getNumber.</p>
|
|
|
27 |
|
|
|
28 |
<h2>Markup</h2>
|
|
|
29 |
<pre><code class="language-markup"><p id="output">Please enter a valid number below</p>
|
|
|
30 |
<input id="phone" type="tel">
|
|
|
31 |
</code></pre>
|
|
|
32 |
|
|
|
33 |
<h2>Code</h2>
|
|
|
34 |
<pre><code class="language-javascript">var input = document.querySelector("#phone"),
|
|
|
35 |
output = document.querySelector("#output");
|
|
|
36 |
|
|
|
37 |
var iti = window.intlTelInput(input, {
|
|
|
38 |
nationalMode: true,
|
|
|
39 |
utilsScript: "../../build/js/utils.js?1603274336113" // just for formatting/placeholders etc
|
|
|
40 |
});
|
|
|
41 |
|
|
|
42 |
var handleChange = function() {
|
|
|
43 |
var text = (iti.isValidNumber()) ? "International: " + iti.getNumber() : "Please enter a number below";
|
|
|
44 |
var textNode = document.createTextNode(text);
|
|
|
45 |
output.innerHTML = "";
|
|
|
46 |
output.appendChild(textNode);
|
|
|
47 |
};
|
|
|
48 |
|
|
|
49 |
// listen to "keyup", but also "change" to update when the user selects a country
|
|
|
50 |
input.addEventListener('change', handleChange);
|
|
|
51 |
input.addEventListener('keyup', handleChange);
|
|
|
52 |
</code></pre>
|
|
|
53 |
|
|
|
54 |
<h2>Result</h2>
|
|
|
55 |
<div id="result">
|
|
|
56 |
<p id="output">Please enter a valid number below</p>
|
|
|
57 |
<input id="phone" type="tel">
|
|
|
58 |
|
|
|
59 |
</div>
|
|
|
60 |
|
|
|
61 |
<script src="../js/prism.js"></script>
|
|
|
62 |
<script src="../../build/js/intlTelInput.js?1603274336113"></script>
|
|
|
63 |
<script src="./js/nationalMode.js?1603274336113"></script>
|
|
|
64 |
</body>
|
|
|
65 |
</html>
|