how to validate edittext to accept only integers between 25 to 100

5 ビュー (過去 30 日間)
srinija kammari
srinija kammari 2018 年 3 月 13 日
回答済み: Sean de Wolski 2018 年 3 月 13 日
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..

採用された回答

Fangjun Jiang
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
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.
srinija kammari
srinija kammari 2018 年 3 月 13 日
thanks a lot Fangjun Jiang... i got the answer

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

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2018 年 3 月 13 日
Use appdesigner and the numeric edit field with upper and lower limits.

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by