validation code / function to allow only Letters in a text box



validation code / function to allow only Letters in a text box..

Answer / kevin konkle

//A script to format the Name field to only allow letters
//Have this be called off the keypress event of your
textbox control.
function nameFormat(fld, e)
{
var key = '';

//This string contains all characters you want to allow
//It could just as easily be 0123456789 to only allow
numbers.
var strCheck
= 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var whichCode = (window.Event) ? e.which : e.keyCode;

if (whichCode == 13) return true; // Enter
if (whichCode == 8) return true; // Delete

// Get key value from key code
key = String.fromCharCode(whichCode);

// Not a valid key
if (strCheck.indexOf(key) == -1) return false;

//If it is a legal value then add it to the text box
fld.value += key;

return false;
}

Is This Answer Correct ?    21 Yes 17 No

Post New Answer

More JavaScript Code Interview Questions

code to get the coordinates of a Click Event

0 Answers  


code to detect versions of different browsers like internet explorer, netscape, mozilla, opera etc

0 Answers   HCL,


code to create a new window

0 Answers  


communication between main window and new windows

0 Answers  


Create a Menu that can be activated while clicking on Right Mouse button

0 Answers   Nest, TCS,






write a program to detect the user's browser ?

1 Answers   Infosys,


maximizing the main window

0 Answers  


Reading which Character Key was pressed

1 Answers  


how to create an anonymous function

0 Answers  


program that will accept any name and will be stored in an array

2 Answers  


code to images to rollover

0 Answers  


could you please tell me for what javac, javax,swing,awt.*; are using. what is the meaning and differences. and also there are 4 access modifiers in java. public, private, protected, default. what is the meaning of these 4 access modifiers and difference. public is the access modifier void means return data type disp() means function name what mean by static

1 Answers   Infosys,


Categories
  • PHP Code Interview Questions PHP Code (33)
  • JSP Code Interview Questions JSP Code (6)
  • ASP Code Interview Questions ASP Code (5)
  • CGI Perl Code Interview Questions CGI Perl Code (3)
  • JavaScript Code Interview Questions JavaScript Code (63)
  • VB Script Code Interview Questions VB Script Code (20)
  • Shell Script Code Interview Questions Shell Script Code (31)
  • Python Code Interview Questions Python Code (34)
  • WinRunner Code Interview Questions WinRunner Code (1)
  • HTML DHTML XHTML Code Interview Questions HTML DHTML XHTML Code (13)
  • XML Interview Questions XML (43)
  • Scripts_Markup Code AllOther Interview Questions Scripts_Markup Code AllOther (5)