您的位置:首页 > 其它

检验输入框为空以及输入参数只有空格的判断

2015-08-30 18:04 417 查看
#pragma mark 检验输入框为空以及输入参数只有空格的判断 Yes:是空白,或者为空 NO:不是空白
-(BOOL)isEmpty:(NSString *)str{

    if (str) {
        //A character set containing only the whitespace characters space (U+0020) and tab (U+0009) and the newline and nextline characters (U+000A–U+000D, U+0085).
        NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
        
        //Returns a new string made by removing from both ends of the receiver characters contained in a given character set.
        NSString *trimedString = [str stringByTrimmingCharactersInSet:set];
        
        if ([trimedString length] == 0) {
            return YES;
        } else {
            return NO;
        }
    }else{
    
        return YES;
    }
  
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: