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

communication between main window and new windows

1882


how to copy form data between different pages

1929


function to combine two or more arrays

1863


code to keep a page Out of the browser history

1804


how to convert between arrays and strings

2287






code to detect availability of cookies

1925


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

1991


how to transform XML Data into HTML

2075


code to set the main window's size

1901


how to Scroll a DIV content

2328


create Drop-Down Navigation Menus

1868


how to create a Draggable element

2108


write a code that user can choose/alter Body Text Size

1766


I have a doubt regarding including tags in a function. I have written a function in javascript in a html page. The function got called by clicking a button, i want to display the results in same html page by placing tags in the function. (this hmtl page is static page) Is this possible? example: