Solved

Only accept alphanumeric characters into input field?

Posted on 2004-10-17
5
433 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
ID: 12334417
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
ID: 12334507
fab. thanks.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12334509
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
ID: 12334557
wonderful.  thanks.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12336434
You are welcome.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

807 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