1>>验证手机号的正则表达式
-(BOOL) isValidateMobile:(NSString *)mobile
{
//手机号以13, 15,18开头,八个 \d 数字字符
NSString *phoneRegex = @"^(1[3|4|5|7|8])\\d{9}$";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
return [phoneTest evaluateWithObject:mobile];
}
2>>验证邮箱的正则表达式
+ (BOOL) validateEmail:(NSString *)email
{
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:email];
}
3>>验证身份证的正则
+ (BOOL) validateIdentityCard: (NSString *)identityCard
{
BOOL flag;
if (identityCard.length <= 0) {
flag = NO;
return flag;
}
NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
return [identityCardPredicate evaluateWithObject:identityCard];
}
4>>毛玻璃效果
- (UIVisualEffectView *)effectViewWithFrame:(CGRect)frame
{
UIBlurEffect * effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView * effectView = [[UIVisualEffectView alloc]initWithEffect:effect];
effectView.frame = frame;
return effectView;
}
5>>判断字符串中是否含有特定字符串
- (BOOL)isHaveString:(NSString *)string1 InString:(NSString *)string2
{
NSRange _range = [string2 rangeOfString:string1];
if (_range.location != NSNotFound) {
return YES;
}
return NO;
}
6>>判断字符串中是否含有中文
- (BOOL)isHaveChineseInString:(NSString *)string
{
for (NSInteger i = 0; i < [string length]; i++) {
int a = [string characterAtIndex:i];
if (a > 0x4e00 && a < 0x9fff) {
return YES;
}
}
return NO;
}
7>>判断字符串是否全是数字
- (BOOL)isAllNum:(NSString *)string
{
unichar c;
for (int i = 0; i < [string length]; i ++) {
c = [string characterAtIndex:i];
if (!isdigit(c)) {
return NO;
}
}
return YES;
}
8>>截屏
- (void) shootScreen
{
UIGraphicsBeginImageContext(remoteVideoSurface.bounds.size);
[remoteVideoSurface.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image,self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
[SVProgressHUD showSuccessWithStatus:NSLocalizedString(@"success",nil)];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
if (error != NULL)
{
NSLog(@"截图err----%@",error);
}
else //截图保存成功
{
}
}
录像保存到本地// 保存到相册
NSString *sourcePath = lpFileName;
UISaveVideoAtPathToSavedPhotosAlbum(sourcePath,nil,nil,nil);
9>>获取ip地址
+ (NSString *)getIpAddress{
NSString *address = @"error";
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
// retrieve the current interfaces - returns 0 on success
success = getifaddrs(&interfaces);
if (success == 0)
{
// Loop through linked list of interfaces
temp_addr = interfaces;
while(temp_addr != NULL)
{
if(temp_addr->ifa_addr->sa_family == AF_INET)
{
// Check if interface is en0 which is the wifi connection on the iPhone
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"])
{
// Get NSString from C String
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
}
}
temp_addr = temp_addr->ifa_next;
}
}
// Free memory
freeifaddrs(interfaces);
freeifaddrs(temp_addr);
return address;
}
10>>判断文件大小
/**
* MARK:判断文件大小
* @param filePath 文件路径
*/
+ (long long) fileSizeAtPath:(NSString*) filePath
{
NSFileManager* manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:filePath]){
return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
}
return 0;
}