Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to make an InputField that only allows a specific date format to be entered.

I want to display a field hint in the format "dd:mm:yyyy". Once the user clicks on the input field, then the user should be able to enter date values. The user should not be able to enter anything that in not in the correct format. I require the ability to insert a separator of my choice. In the example above, my field separator is ":". The user should not be able to enter any other separator except for the one that I have given.

Can anyone help me?

share|improve this question
    
You need to use something like InputField[Dynamic[var,(test[#])&],String,...] where test will be a test of the date string that is entered by the user to ensure that it conforms to your requirements. –  Mike Honeychurch Feb 8 '13 at 7:37
    
If you are assign inputField value to one varibale,how can we validate with all day,month,year values. –  subbu Feb 8 '13 at 8:05
    
If you use String type of InputField,again we have to convert string format to number format.so If you can use Number type of InputField,it does not allow strings,but it poses another problem of not allowing the specialCharacters. So that's why we have to customize our InputField. according to our needs. –  subbu Feb 8 '13 at 8:24
    
I think what you want is not rigorously possible with InputField (unless Mike's answer is good for you of course). I would rather use multiple PopupMenu's. Try this. –  Rolf Mertig Feb 8 '13 at 9:40

1 Answer 1

Test function:

dateCheck[date_String] := 
 StringMatchQ[date, DatePattern[{"Day", ":", "Month", ":", "Year"}]]

Input field:

InputField[Dynamic[date,If[TrueQ[dateCheck[#]], date = #, date = ""] &], String]

This gives you a variable date that is a string of the form dd:mm:yyyy. If you want to convert it to a list or a number then e.g.

DateList[{date, {"Day", ":", "Month", ":", "Year"}}]

and/or

AbsoluteTime[{date, {"Day", ":", "Month", ":", "Year"}}]
share|improve this answer
    
for validation,where I will specify the min ,max values of day,month,year lists. and also ,If you check with DatePattern ,it will useful only for dates formats only,but in some cases I have 4 and more elements like longitude:latitude:wind:pressure,that time it's not useful.... –  subbu Feb 8 '13 at 9:39
    
@subbu seriously? –  Mike Honeychurch Feb 8 '13 at 11:22
9  
I will not waste my time on these questions anymore. You asked about dates and now you want to know about latitude, wind pressure. Are you taking the piss? –  Mike Honeychurch Feb 8 '13 at 11:25
    
@MikeHoneychurch now the compressed string is naughty... –  Yves Klett Feb 12 '13 at 11:00
    
@YvesKlett if you ask a question about dates and then say but it doesn't work for latitude etc. that is irritating for people who offer answers and wastes everyones time. Not having english as a first language is no excuse in this specific case since it is clear the OP knows how to communicate "latitude", longitude" etc. –  Mike Honeychurch Feb 12 '13 at 21:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.