Number and alphabet

7 views (last 30 days)
john on 7 May 2012
I have edittext and pushbutton.
If I write with "sym(' ')" for example a1 or R2 or alfa34...matlab works good. If I write any text in this format a1 into edittext, then I want to enable pushbutton.
But if the firts is number for example 1a or 45R or 89gama, then matlab generate error. So if I write any text in this format 2a into edittext, then I want to disable pushbutton.
Please, how Can I do this?
Thank you
John D'Errico
John D'Errico on 7 May 2012
Use a regular expression to test for this event.

Sign in to comment.

Answers (1)

Titus Edelhofer
Titus Edelhofer on 7 May 2012
you can use isvarname for this purpose, something like
str = get(handles.edit1, 'string');
if isvarname(str))
set(handles.pushbutton1, 'enable', 'on')
set(handles.pushbutton1, 'enable', 'off')
Walter Roberson
Walter Roberson on 17 May 2012
What difficulties are you encountering?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!