# How can I make a customized InputField for date inputs?

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.

Edit (I have partitioned here to make it clear that longitude:latitude:wind:pressure was added after all the comments below and after my answer. MH)

Another problem that I'm faced with is: if I specify input fields to take a string, then I need to convert a lot of numbers to String and vice versa. I want to avoid that because in some cases I have 4 and more elements like longitude:latitude:wind:pressure

Can anyone help me?

-
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 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 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 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 at 9:40

Your requirements seem all over the place and now you have added latitude, longitude, wind pressure to a question that started out as one about how to enter a formatted date string in an input field!!!! If you expect people to spend time on an answer in the future you have to do better than that. /rant

Test function:

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


Input field:

InputField[Dynamic[date,If[TrueQ[dateCheck[#]], date = #, MessageDialog[
Uncompress["1:eJxTTMoPChZhYGAoLskvUChJzM7MS1coyUhVKMgsLgYAfYsJUA=="]];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"}}]

-
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 at 9:39
@subbu seriously? –  Mike Honeychurch Feb 8 at 11:22
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 at 11:25
@MikeHoneychurch now the compressed string is naughty... –  Yves Klett Feb 12 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 at 21:42