2011-04-18 59 views
0

我有一个问题,当我从UITeField到PHP发布的文字,如果我留一个空格,或者使用奇怪的符号(即!,@,#^,&,{} ...)如何验证UITextField的内容?

我可以阻止IBaction不发送这个无用的文本到服务器?

- (IBAction)sendeTextToServer:(id)sender{ 
    if(textfield.text has any space or other symbols inside){ 
     //Block the text send to server 
    } 
    else 
     //Send the text to server to do something. 
} 

如何验证UITextField的内容?

回答

1

使用正则表达式!我在许多项目中使用RegexKitLite,并取得了很大的成功。

编辑:这是链接形式how to use it上的另一个答案。

+0

参见:http://stackoverflow.com/questions/5393377/objective-c-regex-format-creditcard – magma 2011-04-18 03:07:14

+0

感谢,现在我期待这个页面,还是尽量理解现在 – 2011-04-18 03:08:10

+1

和:HTTP:// www.codinghorror.com/blog/2008/06/regular-expressions-now-you-have-two-problems.html – magma 2011-04-18 03:09:46