How To Clear A Text Window?

The Scarlet Pimp

Supreme Member
Joined
Apr 2, 2008
Messages
1,416
Reaction score
4,457
I'm using this code to make sure that only numbers are added. If letters are typed into the text window then an alert box pops up. But, here's the problem, it doesn't erase the letters.

This means that someone can still send letters rather than numbers, just by clicking the SUBMIT button. How do I make this script delete the text in the window after the alert box is closed?

---

<form>
<input type="text" value="" name="phone" onBlur="if (! this.value.match(/^[0-9ext()-]+$/)) {alert('Phone number must use only these characters: 0-9 ( ) e x t');}" onfocus="this.value=''; this.onfocus=null">
</form>

---

tsp
 
Is it possible to make a text window erase letters AS they're typed? Rather than opening an alert that says to enter numbers?

This would be better... :D

tsp
 
Is it possible to make a text window erase letters AS they're typed? Rather than opening an alert that says to enter numbers?

This would be better... :D

tsp

AS they're typing, it would be tricky due to incompability of some browsers.(you can use some js libraries developed to pass this prob.)
but if u want after fix:

Code:
<html>
<body>
<form>
<script>
function duz(id){
var input = document.getElementById(id);
var val = input.value;
var len = val.length;
var arr = "";
	for(var a = 0;a < len;a++)
	{
		if(val.charAt(a).match(/^[0-9ext()-]+$/))
		{
		arr = arr + val.charAt(a);
		}
	}
input.value = arr;
}


</script>
<input type="text" value="" name="phone" id="idofinput" onBlur="duz('idofinput');" onfocus="this.value=''; this.onfocus=null">

</form>
</body>
</html>

NOTE: Your regular expression is wrong. It misses some characters such as "e"
And it is good to check your inputs in server side, client side can be manipulated
 
1. thanx for the script! :D

2. i was thinking the same thing... i'd love to do this in php. since js can be easily disabled by turning it off in the web browser... :confused:


tsp
 
can i use this script?
if yes then tell me the way how i can use
 
your script is a bit better than mine... :D

the cool part is even if someone c&p info into the text window,
as soon as they move to another text window the data clears.

love messing around with scripts!!! :D

tsp
 
Back
Top