• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

check user input for letters only

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Except being pedantic, alphanumeric script includes alphabetic script, so your error message would be better as "letters only permitted"
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic