how to validate edittext to accept only integers between 25 to 100
5 ビュー (過去 30 日間)
古いコメントを表示
hi everyone... im trying to validate a edit text field to accept integers between 25 to 100 .i have written the following code but im not getting the result.....
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
num=Str2double(get(handles.edit1, 'String'));
if num<=25 && num>=100
warndlg('invalid age');
end
please suggest if any changes are to be made in the code..anykind of help will be appreciated..
0 件のコメント
採用された回答
Fangjun Jiang
2018 年 3 月 13 日
編集済み: Fangjun Jiang
2018 年 3 月 13 日
if num<=25 && num>=100
should be
if num<=25 || num>=100
3 件のコメント
Fangjun Jiang
2018 年 3 月 13 日
str2double(), not Str2double()
Add a breakpoint in your code and run your code line by line to see where is the error.
その他の回答 (1 件)
Sean de Wolski
2018 年 3 月 13 日
Use appdesigner and the numeric edit field with upper and lower limits.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Identification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!