title: How to Ristrict Whitespace in UITextfield?
body: <p>Password validation, every thing is ok, but it allows blank spaces also, how to restrict that one, after entering the password it won't delete it. my password length is 8 characters, it allow only 8 or 4, but its not accept 5 to 7 characters. This is my code. Please check it once. Thanks in advance.</p>
  
  <pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  if([passwrd.text length] &lt; 8)
      return YES;
  else
      return NO;
  }
  
  -(void)textFieldDidEndEditing:(UITextField *)textField{
  //int numberofCharacters = 0;
  BOOL lowerCaseLetter = '\0',upperCaseLetter = '\0',digit = '\0',specialCharacter = 0;
  if([passwrd.text length] &gt;= 8)
  {
      for (int i = 0; i &lt; [passwrd.text length]; i++)
      {
          unichar c = [passwrd.text characterAtIndex:i];
          if(!lowerCaseLetter)
          {
              lowerCaseLetter = [[NSCharacterSet lowercaseLetterCharacterSet] characterIsMember:c];
          }
          if(!upperCaseLetter)
          {
              upperCaseLetter = [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:c];
          }
          if(!digit)
          {
              digit = [[NSCharacterSet decimalDigitCharacterSet] characterIsMember:c];
          }
          if (!specialCharacter &amp;&amp; [[NSCharacterSet punctuationCharacterSet] characterIsMember:c]) {
              specialCharacter = YES;
  
          }
      }
  
      if(specialCharacter &amp;&amp; digit &amp;&amp; lowerCaseLetter &amp;&amp; upperCaseLetter)
      {
          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success"
          message:@"Successfully Created Password"
          delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
          [alert show];
  
      }
      else
      {
          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
          message:@"Please Ensure that you have at least one lower case letter, one upper case letter, one digit and one special character"
          delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
          [alert show];
      }
  
  }
  else
  {
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
      message:@"Please Enter Only 8 Characters"
      delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
      [alert show];
  }
  }
  
  
  - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  [passwrd resignFirstResponder];
  return YES;
  }
  </code></pre>