Solved

Only accept alphanumeric characters into input field?

Posted on 2004-10-17
5
432 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript Case Expression 7 29
how can i count words? 2 42
how can i select 4 28
jQuery - following an example but can I save data server side? 20 46
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

806 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