Force user to input an specific time format

2 ビュー (過去 30 日間)
Cristian Martin
Cristian Martin 2022 年 8 月 27 日
編集済み: dpb 2022 年 8 月 28 日
Hi, how can a I force users to input in a cell of a uitable a specific time format, Hh:mm, and warn trough a message for wrong inputs. Thanks!

採用された回答

Walter Roberson
Walter Roberson 2022 年 8 月 27 日
parts = regexp(INPUT, '^([01]\d|2[0-3]):[0-5]\d$');
if isempty(parts)
reject
end
This assumes that you want 24 hour clock with forced leading 0 and that you do not want to permit 24:00
  1 件のコメント
dpb
dpb 2022 年 8 月 27 日
編集済み: dpb 2022 年 8 月 28 日
GEEZER ALERT
"...and that you do not want to permit 24:00"
Lo! so many years ago had a line of online coal analyzers running under MS-DOS on industrial PCs. The app was built on MS Professional Basic 7.1 with additional assembler for the touchscreen UI and the multichannel analyzer (it was a dual-energy gamma densitometer at heart).
The system at a particular installation began crashing at midnight with a non-trapable error -- took several months of debugging before I finally caught it out--the DATE$/TIME$ function returned 24:00:00, 24:00:01, ... at midnight for roughly 30 seconds before it rolled over to 00:00:31, 00:00:32, ...
A bunch of data-storage arrays were defined with indices by hour from 0:23 and the 24 index caused an out-of-bounds memory address that corrupted BASIC string space and when the garbage collector would run in the background, boom!

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2022 年 8 月 27 日
Only with a lot of trouble -- use a datepicker UI control instead uidatepicker
  3 件のコメント
dpb
dpb 2022 年 8 月 27 日
Lots of callbacks, then, examaning keystrokes...see if anybody has written anything for purpose on FEX.
Cristian Martin
Cristian Martin 2022 年 8 月 27 日
編集済み: Cristian Martin 2022 年 8 月 27 日
I managed to do something with if not from cell edit callback... 😉. If there's no : input user receive a warning message

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDialog Boxes についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by