Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi, I am making a simple website. For the first variable prompt, under the 'delivery' function, I would like the user to input a name. I've already set it up, so they cannot only enter numbers, but when the user enters a combination of number and letters, it still accepts it, and continues with the program.

I would like to to only accept letters.

How can I do this?

Thanks!

Link to code
Posted

use regex to validate, for example :

JavaScript
var letters = /^[a-zA-Z]+$/;
if(inputString.match(letters))
{
    alert('input contains letters only');
}else
{
    alert('invalid input');
}
 
Share this answer
 
You can filter out input. Please see this article with code samples: http://www.javascripter.net/faq/keyboardinputfiltering.htm[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900