Checking if inserted text has numbers
1 回表示 (過去 30 日間)
古いコメントを表示
Hello there. I need to build a program, where an user inserts its name in the dialog box. But the inserted text cannot have numbers or any special symbols. How may program check that and show an information to user?
0 件のコメント
回答 (3 件)
Niels
2017 年 1 月 6 日
in my opinion the easiest way would be
all(isletter(expressionString))
>> all(isletter('haj%kj'))
ans =
logical
0
>> all(isletter('hajkj'))
ans =
logical
1
0 件のコメント
Stephen23
2017 年 1 月 5 日
編集済み: Stephen23
2017 年 1 月 5 日
>> all(isstrprop('onlyalpha','alpha'))
ans = 1
>> all(isstrprop('1234_+!%%','alpha'))
ans = 0
4 件のコメント
Stephen23
2017 年 1 月 9 日
編集済み: Stephen23
2017 年 1 月 9 日
I wouldn't use a try - catch for that. That is a bit brutal. Just put the code in a for-loop and break out of the loop when the user enters valid input. The for loop should have five or so iterations, after which you can conclude that the user is not interested in supplying valid data anyway so you might as well terminate the code.
José-Luis
2017 年 1 月 5 日
strTrue = 'Abs';
strFalse = '!abs!!!';
expr = '^[A-Za-z]';
a = isempty(regexp(strTrue,expr))
b = isempty(regexp(strFalse,expr))
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!