MATLAB: Re entering a user inputted variable

inputmarginsre initializinguservariables

hello, i just have one very very minor issue with another area in which i need to make sure the number is ten digits long after everything is taken out, and if it is not ten digits long, it needs to ask to enter stra again and re run the program.
i have clear;clc;
stra =input('Enter a 10 digit phone number: ','s');
num2str(stra());
nbrs = regexpi(stra, '\d');
nbrx = stra(nbrs);
num2str(nbrx());
cnt=length(nbrx);
if length(nbrx)<10
clear;clc; disp('Invalid input'); strb=input('Please enter a TEN digit phone number: ','s'); stra=strb;end
a=(nbrx(1));
although when i run this fragment i get an error. any thoughts on how to fix this? i imagine its simple. its just when i re enter stra it does not put it through the first part of the program that converts stra into what nbrx is. i get an error that nbrx is undefined.

Best Answer

Here's one way to do it:
defaultValue = '(123)456 - 7890';
titleBar = 'Enter the number';
userPrompt = 'Enter the 10 digit phone number';
numberCount = 0;
while numberCount < 10
% Ask user for a number.
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
strInput = char(caUserInput)
numberCount = 0;
theNumber = [];
[a1 a2 a3 a4 a5 a6 indexes] = regexpi(strInput, '\d')
numberCount = length(a4)
onlyTheNumbers = char(a4)
fprintf('The numbers = %s\n', onlyTheNumbers);
end
msgbox('Success!');