2011-04-18 49 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