textField validation

Discussion in 'iOS Programming' started by sujithkrishnan, Aug 18, 2008.

  1. sujithkrishnan macrumors 6502

    Joined:
    May 9, 2008
    Location:
    Bangalore
    #1
    Hi...


    Is there any EASY way to validate the texfields are empty or not ??

    if (textfield.text ==nil) is valid only if i didnt tappped the textfield.
    If a tap the textfield and dont enter anything textfield.text is not nil

    Then i want to check for [textfield.text isEqaultoString@""]

    So for a single textfield i want to check like following code...

    Code:
    
    if(textfield.text == nil)
    ALERT: text empty
    else if(textfield.text isEqualToString:@""])
    ALERT:text empty
    else
    proceed
    
    If i am giving if(textfield.text isEqualToString:mad:""]) alone also not enough..

    Is there any other easy validation??? Or i want to write both conditions for all the textfields ????
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Well you could combine your two tests safely as

    Code:
    if (textfield.text == nil || [textfield.text isEqualToString:@""])
    {
    // Empty
    }
    
     

Share This Page