-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextboxClipboardExample01.htm
More file actions
executable file
·33 lines (28 loc) · 1.02 KB
/
Copy pathTextboxClipboardExample01.htm
File metadata and controls
executable file
·33 lines (28 loc) · 1.02 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Textbox Clipboard Example</title>
<script type="text/javascript" src="EventUtil.js"></script>
</head>
<body>
<p>You can only paste strings that are comprised only of numbers in the textbox below.</p>
<form method="post" action="javascript:alert('Form submitted!')" id="myForm">
<div>
<label for="txtPhone">Type a phone number:</label><br>
<input type="text" id="txtPhone" name="phone" value="">
</div>
</form>
<script type="text/javascript">
(function(){
var textbox = document.getElementById("txtPhone");
EventUtil.addHandler(textbox, "paste", function(event){
event = EventUtil.getEvent(event);
var text = EventUtil.getClipboardText(event);
if (!/^\d*$/.test(text)){
EventUtil.preventDefault(event);
}
});
})();
</script>
</body>
</html>