Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Only accept alphanumeric characters into input field?

Posted on 2004-10-17
5
Medium Priority
?
438 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

719 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