proper format

G

gk

i want my user should input data in this format "dd/MM/yyyy HH:mm:ss" .
if not i want to show him a message to enter input in that proper
format . how ?
 
Z

zero

i want my user should input data in this format "dd/MM/yyyy HH:mm:ss" .
if not i want to show him a message to enter input in that proper
format . how ?

You can use regular expressions.

use
class Pattern:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html
and class Matcher:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Matcher.html

or String:matches(String regex)
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#matches
(java.lang.String)

The javadoc for class Pattern shows how to construct regular expressions.

Basically you get the input string, match it against a regular expression,
and if it doesn't match, tell the user to try again.
 
V

Viator

Can you please spare a bit of time to explain YOUR problem. Where are
you gettign the data(input) from. What kind of user interface it is.
Where do you show the message. Do you want to strict the user to enter
only allowed format or you want to check the format after entry is done.
 
L

Luc The Perverse

Viator said:
Can you please spare a bit of time to explain YOUR problem. Where are
you gettign the data(input) from. What kind of user interface it is.
Where do you show the message. Do you want to strict the user to enter
only allowed format or you want to check the format after entry is done.

Likewise, please take time to quote the person you are replying to ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top