MATLAB: How to set regexp expression for HH:MM dd.mm.yyyy format

guiregexp

Hy, I have a gui where i want to check the user input dateSTOP for the format. The format should be in this order HH:MM dd.mm.yyyy with all the characters used (eg 02:03 01.03.2014 not 2:3 1:3.14). I use this code…
control = regexp(dateSTOP,'[012][0-9]:[0-6][0-9] [1-9]|([012][0-9])|(3[01])).([0][1-9]|1[012]).\d\d\d\d')
if(numel(control)==0)
errordlg('Use format: 05:00 04.09.2014','modal'));
else
...
end
but that also allows the short version. How to rewrite the regexp expression to have all characters?

Best Answer

There is a function that does the parsing for you.
Try
t = datetime(dateSTOP,'InputFormat','hh:mm dd.MM.yyyy')
See
doc datetime