Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

how to create an anonymous function

2169


communication between main window and new windows

2178


function to combine two or more arrays

2145


how to transform XML Data into HTML

2385


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

2174


how to create a Draggable element

2435


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

2127


how to create a Custom Scrollbar

2550


code to sorting an array of objects

2489


Reading which Non-Character Key was pressed

2247


how to pass data between pages using Cookies

2452


How to encode and decode URL strings?

2308


how to pass data between pages using Frames

2728


code to positioning of window in certain dimensions

2128


advance the focus to next consecutive fields when Enter Key is pressed

2260