MATLAB Answers

check String for letters ?

7 views (last 30 days)
Max Müller
Max Müller on 27 Sep 2014
Edited: per isakson on 27 Sep 2014
Hey Guys, I have an Editbox and I want to start my program only if the Editbox Input are only numbers. Unfortunately, get(handle.editbox,'String') gives the Input back as String. So how can i check whether the user only entered numbers ?
isnumeric wont work i guess

  1 Comment

Max Müller
Max Müller on 27 Sep 2014
see ya tomorrow

Sign in to comment.

Accepted Answer

per isakson
per isakson on 27 Sep 2014
Edited: per isakson on 27 Sep 2014
One way
is_num = not( isnan( str2double( str ) ) );
or
is_num = not( isnan( str2double( get(handle.editbox,'String') ) ) );
&nbsp
Won't work if user inputs "nan" :-(
>> isnumeric( nan )
ans =
1

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.