Thursday, July 29th 2010, 1:32pm UTC+2
You are not logged in.
|
|
Source code |
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 |
<html>
<head>
<script type="text/javascript">
MS_restrict_field = function(formname, id_or_name, chars) {
var obj = (document.getElementById && document.getElementById(id_or_name) != null)
? document.getElementById(id_or_name) : ((document[formname][id_or_name] != null)
? document[formname][id_or_name] : '');
if(obj.type == "text" || obj.type == "textarea") {
obj.timer = "";
obj.chars = chars;
obj.onkeypress = obj.onkeydown = function() {
var self = this;
controll = function() {
for(var t='',x=0; x<self.value.length; ++x) {
if(self.chars.indexOf(self.value.charAt(x))>-1) {
t += self.value.charAt(x);
}
}
self.value = t;
};
this.timer = setTimeout(controll,1);
};
obj.onkeyup = function() {
clearTimeout(this.timer);
};
}
};
</script>
</head>
<body onload="MS_restrict_field('restrictform','field','.0123456789')">
<form name="restrictform">
<input type="text" name="field" id="field" />
</form>
</body>
</html>
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 |
// JS
function restrict (pTextField) {
var allowedChars = /[0-9a-z]/;
if (!allowedChars.test (pTextField.value)){
pTextField.value = pTextField.value.replace (/([^0-9a-z])/g, "");
}
}
<!-- HTML -->
<input type="text" onkeydown="restrict (this);" onkeyup="restrict (this);" onblur="restrict (this);" onclick="restrict (this);" />
|
This post has been edited 1 times, last edit by "sonar" (Apr 28th 2005, 7:12pm)

