» in my experience...
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Elsewhere...
·8bit joystick ·a list apart ·amishrobot ·arcadezen ·antipixel ·boxes and arrows ·black belt jones ·curiousLee ·daring fireball ·design interact ·design not found ·everything hurts ·forwarding address: osx ·gridface ·info design ·izzywizzy ·jon madisons ·joshua kaufman ·k10k ·kalsey ·kelake ·kuro5hin ·the lion's web(log) ·louise ferguson ·memepool ·metafilter ·quinn macdonald ·railhead design ·rentzsch ·surfin' safari ·the onion ·winterspeak ·web-graphics ·xblog ·zen haiku Here at IMX
Recent posts...
·Unreal 2 is... uh, not so great. ·Video Game legitimization. ·Random access info architecture. ·Too soon. ·I want my P2P. ·Detecting alphanumeric characters in JavaScript. ·Having some copyright fun with GarageBand. ·Are five minute compositions worth anything? ·Yeah, GarageBand is cool. ·Taking the plunge (again).
Categorically speaking...
·AOL
·Apple and Mac OSX ·Books and Reading ·Business Technology ·Design ·Design Technology ·Effort ·Gaming ·Information Architecture ·Interaction Design ·Internet Consulting ·JavaScript ·O'Reilly Emerging Tech Conference ·Personal ·Photography ·Random ·Software ·U and I ·UI Programming ·Usability ·User Experience ·Web Browsers ·Weblogs and Blogging ·When Bad Things Happen to Good BMW's Memes R' Us
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Detecting alphanumeric characters in JavaScript.
[ Posted by Dan on January 30, 2004 | 4 Comments ] I approached the problem by using ASCII character codes. If you have BBEdit, there's a pallette that shows all of those code next to their characters, so I used that to write an annoyingly long if statement with four "or" statements and two "and" statements imbedded in an or statement. Annoying, but effective. Here it is...
function alphaNumericCheck(theChar) {
if ((theChar < 48) || (theChar > 122) ||
((theChar > 57) && (theChar < 65)) ||
((theChar > 90) && (theChar < 97)) ) {
return false;
} else {
return true;
}
}
To call the function, you would say something like...
<input type="button" name="foo" value="my button"
onclick="alphaNumericCheck(this.value.charCodeAt(0))">
The part that says charCodeAt(0) will return the ASCII number for the character at the zeroth position in the string (the first character). The function will take that character and return "false" if it's not a number, a capital letter or a lowercase letter, and "true" if it is alphanumeric. Try it.
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Copyright © 2001 - 2003 by Daniel Kapusta | ||||||||||||||||||||||||||||||||||||||||||||