-
Notifications
You must be signed in to change notification settings - Fork 0
/
phoneinput.html
57 lines (57 loc) · 2.06 KB
/
phoneinput.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE HTML>
<!--
Hello! Welcome to my personal website. Feel free to look around or get in touch with me if
you wish to know more. I typically respond to emails within a couple of hours.
This stylesheet is a customized version of Forty by HTML5 UP used under the CCA 3.0 license.
I love doggo memes.
-->
<html>
<head>
<title>Phone Form</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
</head>
<body>
<script>
function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
function formatphone(num) {
numbers = pad(num, 10);
formatted = "(" + numbers.substr(0, 3) + ') ' + numbers.substr(3, 3) + '-' + numbers.substr(6,4);
return formatted;
}
start = 0
$(document).keydown(function(e) {
start += e.which;
document.getElementById("phonenum").innerHTML = formatphone(start);
document.getElementById("yourinput").innerHTML += e.key;
$("textarea#mobilebox").val("");
document.getElementById("found").innerHTML = "";
});
function resetnumber() {
start = 0;
document.getElementById("phonenum").innerHTML = "(000) 000-0000";
document.getElementById("yourinput").innerHTML = "";
}
function foundnumber() {
document.getElementById("found").innerHTML = "sure. go again.";
resetnumber();
}
</script>
<p>Press any key to increment number by keycode.</p>
<h1>Is this your phone number?</h1>
<span id="phonenum" style="font-size: 50px;">(000) 000-0000</span>
<br/><br/>
<button onclick="foundnumber()">yes</button>
<button onclick="resetnumber()">reset</button>
<span id="found"></span>
<br/><br/>*Click this box if on mobile for keyboard: <textarea id="mobilebox" cols="5" rows="1"></textarea><br/>
<br/><br/><br/>
Your input so far:
<p id="yourinput" style="width: 100%; word-wrap: break-word;"></p>
</body>
</html>