Click to See Complete Forum and Search --> : Validate user input using jscript
Nimisha
06-03-2003, 04:20 AM
Hi
I need to check the text entered by users and not allow then to put any "<" or ">" characters in the text.
How would I go about validating the input using jscript?
Ta
Nimisha
Gollum
06-03-2003, 04:44 AM
Well, one way is to use the onblur event handler of the text box to check the value...
<input
type=text
onblur="if ( this.value.search(/[<>]/) != -1 ) { alert('You cannot have < or > in this field'); this.value = this.value.replace(/[<>]/g,''); this.focus(); }"
>
another way is to just stop the user from entering those characters...
<input
type=text
onkeyup="if ( this.value.search(/[<>]/) != -1 ) { alert('< and > not allowed'); this.value = this.value.replace(/[<>]/g,''); }"
>
Nimisha
06-04-2003, 05:24 AM
Thanks guys , will try this out.
ta
Nimisha