Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

alphanumeric validation

 
jone wiilum
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
 
Karthik Srikanti
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}
 
jone wiilum
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Prithiraj Sen Gupta
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic