• Post Reply Bookmark Topic Watch Topic
  • New Topic

check user input for letters only  RSS feed

 
phi tran
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone!

So I decided to read up on Regular expression. After some reading I wrote a very simple program to check my knowledge on regex. My question, would this(code below) be the best way to use regex and checking the user input?

Thanks for taking the time to read this

Check out the code below:

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
phi tran wrote:My question, would this(code below) be the best way to use regex and checking the user input?

The regex looks fine, providing you don't want to allow spaces - ie, the input must be a single word made up entirely of letters (so nothing like "can't" or "by-product").

And I think the loop is correct (at least it'll work); however, I suspect that if you wanted to input anything else afterwards, you'd have to skip to a new line before you do.

The reason being that I'm pretty sure if I did something like:
  enter name:
  Winston The Great <Enter>
I'd get
  Hello Winston. Welcome

Winston
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Except being pedantic, alphanumeric script includes alphabetic script, so your error message would be better as "letters only permitted"
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!