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

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..

 Accepted Answer

if num<=25 && num>=100
should be
if num<=25 || num>=100

3 Comments

i accept this mistake but im still not getting the warning.. thanks
str2double(), not Str2double()
Add a breakpoint in your code and run your code line by line to see where is the error.
thanks a lot Fangjun Jiang... i got the answer

Sign in to comment.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!