how to validate edittext to accept only integers between 25 to 100
5 views (last 30 days)
Show older comments
srinija kammari
on 13 Mar 2018
Answered: Sean de Wolski
on 13 Mar 2018
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 Comments
Accepted Answer
Fangjun Jiang
on 13 Mar 2018
Edited: Fangjun Jiang
on 13 Mar 2018
if num<=25 && num>=100
should be
if num<=25 || num>=100
3 Comments
Fangjun Jiang
on 13 Mar 2018
str2double(), not Str2double()
Add a breakpoint in your code and run your code line by line to see where is the error.
More Answers (1)
Sean de Wolski
on 13 Mar 2018
Use appdesigner and the numeric edit field with upper and lower limits.
0 Comments
See Also
Categories
Find more on Data Type Identification 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!