How to restrict text input in hex number range?

2 views (last 30 days)
Making a GUI for users to input hex numbers. How can I prevent input letter(s) not in the hex number range? like instead ABCD, FFFF, what if some one typing in KKKK, WXYZ? Is there any matlab input filter to reject that?

Answers (1)

Walter Roberson
Walter Roberson on 25 May 2012
If you are using a uicontrol('Style','edit'), then you can set its keypressfcn callback, which would allow you access to every key as it was pressed.
Caution: the String value of the edit box will not be the full accumulated set of characters when you access it within the keypressfcn ! (We don't know why... that's just the way it is.) You will need to store the keys away and then transfered the stored keys into the String property when the Callback function is finally triggered.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!