フィルターのクリア

How to restrict input string in length,symbols, char and numbers

4 ビュー (過去 30 日間)
Johnny Birch
Johnny Birch 2020 年 3 月 7 日
コメント済み: Johnny Birch 2020 年 3 月 7 日
I am developing an app where the user inputs a string which need several restrictions. How can I check that the input is in the format 'LLL-NN-NNN' where L is lettes (A-Z) and N is numbers (0-9), and the string have to be exactly 10 characters in total.

採用された回答

Stephen23
Stephen23 2020 年 3 月 7 日
編集済み: Stephen23 2020 年 3 月 7 日
>> str = 'XYZ-99-123'; % okay
>> ~isempty(regexp(str,'^[A-Z]{3}-\d{2}-\d{3}$','once'))
ans = 1
>> str = 'XYZ-99-ABC'; % not okay
>> ~isempty(regexp(str,'^[A-Z]{3}-\d{2}-\d{3}$','once'))
ans = 0
>> str = '666-99-123'; % not okay
>> ~isempty(regexp(str,'^[A-Z]{3}-\d{2}-\d{3}$','once'))
ans = 0
>> str = 'hello world'; % not okay
>> ~isempty(regexp(str,'^[A-Z]{3}-\d{2}-\d{3}$','once'))
ans = 0
Use that logical output to either throw an error, or ask the user to supply new input data, or whatever suits your process.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by