You can use regular expressions. The code will go something like this -
if any(regexp(str,'[^_a-zA-Z0-9]+'))
<error condition>
end
You will need to use a more sophisticated regEx format if you need more robust checking. Like:
if any(regexp(str,'^[a-zA-Z_][a-zA-Z0-9_]*$'))
<valid>
else
<invalid>
end
2 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/213773-anyone-know-the-error-checking-for-special-characters#comment_281173
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/213773-anyone-know-the-error-checking-for-special-characters#comment_281173
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/213773-anyone-know-the-error-checking-for-special-characters#comment_281236
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/213773-anyone-know-the-error-checking-for-special-characters#comment_281236
Sign in to comment.