Test if string is alphanumeric in Javascript

function isAlphaNum(alphane) {
	var numaric = alphane;
 
	for(var j=0; j<numaric.length; j++) {
		var alphaa = numaric.charAt(j);
		var hh = alphaa.charCodeAt(0);
 
		if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123)) {
		} else {
			return false;
		}
		}
	return true;
}

Download this snippet

This Javascript function tests, if a given string consists only of alphanumeric characters.

Twitter Twitter

4 Comments to “ Test if string is alphanumeric in Javascript”

  1. Anonymous  on Sep 25, 2009

    ZaPOC7 <a href="http://nrypnbwijxpx.com/">nrypnbwijxpx</a>, [url=http://ickddyxdstwh.com/]ickddyxdstwh[/url], [link=http://hbgwqnjprlzq.com/]hbgwqnjprlzq[/link], http://xhvpwavkksaq.com/

  2. Anonymous  on Feb 19, 2010

    A much simpler way is to use a regular expression:

    function isAlphaNum(alphane) {
    return (/^[a-z0-9]*$/i).test(alphane);
    }

  3. Anonymous  on Feb 21, 2010

    znaPdz <a href="http://kojjtgizbpxk.com/">kojjtgizbpxk</a>, [url=http://zldlbuotwbdu.com/]zldlbuotwbdu[/url], [link=http://eihtgxvncndk.com/]eihtgxvncndk[/link], http://wquncdpvaczc.com/

  4. Anonymous  on Mar 15, 2010

    7vsLNf <a href="http://dfzguiyhwbuz.com/">dfzguiyhwbuz</a>, [url=http://zmiruufmgbjj.com/]zmiruufmgbjj[/url], [link=http://sagvuxbboyfr.com/]sagvuxbboyfr[/link], http://ldhxtwpouadd.com/

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>