Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textbox characters restriction 1

Status
Not open for further replies.

ghorr

Programmer
Sep 16, 2002
29
RO
i need a script that can set restrictions concerning the characters i can enter in a textbox ...
for example i want a NAME field that would not allow the user to enter some special characters (E.G. '%','^','&','*')
help me pls ;)
 
one more thing ... it should not allow this on keyPress ... not on 'Submit'
 
Here's a quick example:

Code:
<script>

function restrict( el ) {

	el.value = el.value.replace( /[^a-zA-Z-']+/i, '' );
}

</script>

<input type=&quot;text&quot; onkeyup=&quot;restrict( this );&quot; />

I've used
Code:
onkeyup
'cause that makes it a little simpler than your idea of
Code:
onkeypress
.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top