Solved

Only accept alphanumeric characters into input field?

Posted on 2004-10-17
5
428 Views
Last Modified: 2006-11-17
Hello.
I have a text input field in a form ... and I wish to only access alphanumeric characters. a-z A-Z 0-9 and the space bar.
Can u help?

I believe I need to modify this :- onkeyup="this.onchange();"  onchange="this.value=this.value.replace(/ /g,'_').replace(/[^0-9A-Z]/gi,'');"

but to be brutally honest I don't understand it ... so I'm hoping you can help modify so I can slip it into this:

<input name="pay_fullname" type="text" width="32" maxlength="80" class="styleregister3_ht">



Does this make sense?
Richard
0
Comment
Question by:rcbuchanan
  • 3
  • 2
5 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
Comment Utility
Like this:



<input name="pay_fullname" type="text" width="32" maxlength="80" class="styleregister3_ht"
 onkeyup="this.onchange();"  onchange="tV=this.value;if(tV.match(/[^a-z0-9 ]/))this.value=tV.replace(/[^a-z0-9 ]/gi,'');">



0
 

Author Comment

by:rcbuchanan
Comment Utility
fab. thanks.
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
And if you want the space character to be translated to undersore character, then use this:


<input name="pay_fullname" type="text" width="32" maxlength="80" class="styleregister3_ht"
 onkeyup="this.onchange();"  onchange="tV=this.value;if(tV.match(/\W/))this.value=tV.replace(/ /g,'_').replace(/\W/g,'');">


0
 

Author Comment

by:rcbuchanan
Comment Utility
wonderful.  thanks.
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
You are welcome.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now