File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes alphanumeric  validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "alphanumeric  validation" Watch "alphanumeric  validation" New topic
Author

alphanumeric validation

jone wiilum
Ranch Hand

Joined: Mar 24, 2007
Posts: 49
hi,
i am trying to run a simple html page with a java script validation for alphanumeric validation

i have two text fields user name and password.
in which username is must be alphanumeric e.g. jone345 or jone234dd like that.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Javascript supports regular expressions.
Have you looked into this approach?
http://www.google.com/search?hl=en&q=JAVASCRIPT+REGEX+TUTORIAL&btnG=Google+Search


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Karthik Srikanti
Greenhorn

Joined: Sep 20, 2006
Posts: 11
You can try this...


function isAlphabetic(sText)
{
var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890* ";
var IsAlphabetic=true;
var Char;


for (i = 0; i < isalphabetic ="="">
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsAlphabetic = false;
}
}
return IsAlphabetic;
}


{ SCJP, SCWCD, SCBCD, OCA (DBA) }
jone wiilum
Ranch Hand

Joined: Mar 24, 2007
Posts: 49
Thanks
Prithiraj Sen Gupta
Ranch Hand

Joined: Sep 13, 2006
Posts: 92
You can try this one-->

function validate(){
var usrid=document.getElementById("txtUserid"); //txtUserid-->ID of textbox
var alphanum=/^[0-9a-bA-B]+$/; //This contains A to Z , 0 to 9 and A to B
if(usrid.value.match(alphanum)){
return true;
}else{
alert(Put a Valid Userid Name);
return false;
}
}


For simple validations you can check tizag.
Or if you want to make hi-fi validations check Quirksmode The Latter one is based on DOM -->Document Object Model. You learn the simple validation just for getting the some degree of idea about javascript without DOM and then proceed to handle with DOM.
[ April 08, 2007: Message edited by: Prithiraj Sen Gupta ]
sanjay varmora
Greenhorn

Joined: Apr 04, 2007
Posts: 6
you can try also using like this,

function alphnumericValidate(event)
{
var val;
if (navigator.appName == "Microsoft Internet Explorer")
val = window.event.keyCode;
else if (navigator.appName == "Mozilla")
val = event.keyCode;
if(val>=48 && val<=57)
{
var txt=obj.value;
if(txt.length<=4)
return true;
else
return false;
}
else if(val==8)
return true;
else
return false;
}
sanjay varmora
Greenhorn

Joined: Apr 04, 2007
Posts: 6
This is the better options for you can try also using like this,

function alphnumericValidate(event)
{
var val;
if (navigator.appName == "Microsoft Internet Explorer")
val = window.event.keyCode;
else if (navigator.appName == "Mozilla")
val = event.keyCode;
if(val>=48 && val<=57 || val>=65 && val<=90 || val>=97 && val<=122)
{
var txt=obj.value;
}
else if(val==8)
return true;
else
return false;
}


this functions working properly in Internet explorer and also in mozila fire fox...

regards, sanju...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: alphanumeric validation