-
Notifications
You must be signed in to change notification settings - Fork 0
/
numbers.html
84 lines (82 loc) · 3.12 KB
/
numbers.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>How to parse a number</title>
<link rel="stylesheet" href="code.css" type="text/css" media="screen" title="no title" charset="utf-8">
<style type="text/css">
body {
color: #111;
font-size: 110%;
font-family: "Georgia", "Times New Roman", "Times", serif;
}
h1 {
font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
text-align: center;
}
.input {
text-align: center;
}
input {
font-size: 1.25em;
margin: 0 auto .5em;
padding: .25em;
width: 90%;
}
button {
background-color: #0a0;
border: none;
border-radius: 3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
-o-border-radius: 3px;
-icab-border-radius: 3px;
-khtml-border-radius: 3px;
-ms-border-radius: 3px;
color: #fff;
cursor: pointer;
font-size: 1.5em;
margin: auto;
padding: .25em .5em;
width: auto;
}
p {
line-height: 1.5em;
}
</style>
<script type="text/javascript" charset="utf-8">
function parseNumber(text) {
return text && typeof text == "string" ? text.replace(/\D+/g,"") : "";
}
function go() {
alert("SSN: '123-45-6789' -> '" + parseNumber("123-45-6789") + "'");
alert("EIN: '12-3456789' -> '" + parseNumber("12-3456789") + "'");
alert("Telephone: '+1-555-555-1212' -> '" + parseNumber("+1-555-555-1212") + "'");
alert("Junk: '0[9mq3409mt34 y \t89g9825ypt9fy\\8ng2;' -> '" + parseNumber("0[9mq3409mt34 y \t89g9825ypt9fy\\8ng2;") + "'");
alert("It handles null: '" + parseNumber(null) + "'");
alert("and undefined: '" + parseNumber(undefined) + "'");
alert("and empty strings too: '" + parseNumber("") + "'");
};
window.onload = function() {
document.getElementById('text').focus();
}
</script>
</head>
<body>
<h1>Dear All Banks,</h1>
<section>
<p>Here is code for your website, so that you can parse numbers, like SSNs, EINs, Telephone #s, etc. entered by your customers instead of locking them out of their online account when they don't read the mostly invisible text on your page that tells them not to enter any dashes, <em>because every other time in their entire life they write them with dashes</em>. Seriously, computers are here to help your customers, and they are really good at stuff like this.</p>
<p>Here, try it. Enter anything that looks like an SSN, EIN, Telephone #, whatever. Feel free to include dashes, commas, periods, and any other junk: </p>
<p class="input">
<input type="text" id="text" onclick="this.select(); return false;">
<button onclick="alert('\'' + parseNumber(document.getElementById('text').value) + '\''); return false;">Parse it</button>
</p>
<p><a href="#" title="Parse some numbers!" onclick="go(); return false;">Or click here</a> to see some examples.</p>
<p>So here you go, view source, take this one-liner, use it, improve on it, continue to keep your other security measures, and still make your customers happy.</p>
</section>
<footer>
<p class="copyright">Copyright © 2010 <a href="http://briancavalier.com">Brian Cavalier</a> — take the code, please</p>
</footer>
</body>
</html>