如何检查字符串值是否为0到9?

hac*_*ker 1 iphone ipad ios

我有一个iphone应用程序,我想检查字符串值是否从0到9.如果是这样,我想做其他事情.有人知道怎么做这个吗?

小智 6

if (string.length == 1 && [string characterAtIndex:0] >= '0' && [string characterAtIndex:0] <= '9') {
    // do something
}
Run Code Online (Sandbox Code Playgroud)

这将检查字符串是否正好是1个字符长,该字符是0,1,2,3,4,5,6,7,8或9.