Solved

Only accept alphanumeric characters into input field?

Posted on 2004-10-17
5
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

732 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