I have a GUIDE GUI where I ask the user to enter in their name. It should execute an error dialog if they enter numerical characters, a mix of string and numerical characters, or a blank box.
The issue is that when I enter in numbers or a mix of string and numerical characters, then it is outputting Error Code II
(1st elseif
statement) instead of Error Code III
(entering in numbers only) or Error Code IV
(entering numbers and strings). Input would be greatly appreciated.
Here's essentially what I have:
if isempty(editString)
errordlg('Please enter a name into the text-box. We thank you in anticipation.',...
'Error Code I');
return
elseif char(editString) > 12
errordlg('Please enter a name that is less than 12 characters long. Thank you.',...
'Error Code II');
return
elseif isa(editString, 'integer')
errordlg('Please enter a name, not numbers. Thank you.', 'Error Code III');
return
elseif isa(editString, 'integer') && isa(editString, 'char')
errordlg('Please enter a name without mixing numbers & characters. Thanks.',...
'Error Code IV');
else
delete(gcf)
gui_02
end
Well,
isa()
function doesn' t work in this case because all you read fromEdit Text
isstring
in other wordschar
. Thus, if you even writeisa('123', 'integer')
, function returns0
not1
. Anyway, thanks to MATLAB there is a function:isstrprop()
determines whether string is of specified category such asinteger
,char
..Check the code below:
It doesn' t look elegant but works.