This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Are you rather asking about how to verify the format of a String? If that is the case, then a regular expression would certainly fit the bill well. If you'd like more information on how to use regular expressions in Java, just ask.
what i mean is that the user enters the registration number and it is stored as a variable in that format. or is there any way to make sure that the user enters it in that format
Joined: Dec 10, 2001
How does the user enter the value? Is it a text field on a form in a web page? Is it through a JOptionPane, or a frame-based application? Is it through the command prompt?
No matter the input mechanism, you can certainly format the input (which is harder depending on how many different user-input patterns you want to be able to handle), as well as verify that the input format is correct, and then prompt the user to input the value again if the format is wrong (which is much easier than the previous option).
To verify the pattern of the input data, you could make use of a few of the methods in the String class and the Character class to be able to analyze the overall length, as well as the type of each character individually.
A less tedious solution to verify the patter of the input data would be to make use of regular expressions. For what I hope is an easy introduction to that subject, take a look at the two articles I wrote for the JavaRanch Journal. (Search for "regex" on that page.) [ May 27, 2004: Message edited by: Dirk Schreckmann ]