Prevent typing string in edit text
显示 更早的评论
I have a problem. I want to create a edit text and then when I type a string in it, it will display nothing like a empty. That is to say it allows only numbers. I found some ways but they use push button for checking. Please help me.
Thank you in advance.
采纳的回答
更多回答(3 个)
Walter Roberson
2016-3-31
0 个投票
You can use a variation of http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples/content/GUI_37.m
Daveed Daveed
2022-7-31
Hello. i was walking around here and i thought the following solution might be usefull for future people (may be the past time traveler :) )
function prevent_string(textbox_control)
if textbox_control.String ~= "" && isnan(str2double(textbox_control.String))
textbox_control.String = "";
end
Walter Roberson
2022-7-31
These days you would use a
uieditfield('numeric')
which requires uifigure() (and will not work for traditional figures)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!