• Post Reply Bookmark Topic Watch Topic
  • New Topic

String Problem  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem with Payroll program I want to input only a alphabet for the name , if the
user's input a number, for example, "sam4pl3" or "123 " the program will show a message "Number is
not allowed" although the string is alphanumeric, then ask the user to input again, if the
user commits 3 times error the program will be executed.


thanks in advance.
 
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To search whether the string is alphanumeric, you will have to use regex..
 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um, no, you don't *have* to use regex. You can loop over the characters of the String, testing each with an appropriate method from the Character class.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will suggest you to make use of Pattern class.

Refer here.

Thanks,
Ashwini Kashyap | www.infocepts.com
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!