手机号验证

/*
手机号码 13[0-9],14[5|7|9],15[0-3],15[5-9],17[0|1|3|5|6|8],18[0-9]
移动:134[0-8],13[5-9],147,15[0-2],15[7-9],178,18[2-4],18[7-8]
联通:13[0-2],145,15[5-6],17[5-6],18[5-6]
电信:133,1349,149,153,173,177,180,181,189
虚拟运营商: 170[0-2]电信 170[3|5|6]移动 170[4|7|8|9],171 联通
上网卡又称数据卡,14号段为上网卡专属号段,中国联通上网卡号段为145,中国移动上网卡号段为147,中国电信上网卡号段为149
*/
-(BOOL)isMobilePhone:(NSString *)phoneNum
{
NSString * MOBIL = @"^1(3[0-9]|4[579]|5[0-35-9]|7[01356]|8[0-9])\\d{8}$";
NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBIL];
if ([regextestmobile evaluateWithObject:phoneNum]) {
return YES;
}
return NO;
}

是否是移动号码

/**
* 中国移动:China Mobile
* 134[0-8],13[5-9],147,15[0-2],15[7-9],170[3|5|6],178,18[2-4],18[7-8]
*/
-(BOOL)isCMMobilePhone:(NSString *)phoneNum
{
NSString * CM = @"^1(34[0-8]|70[356]|(3[5-9]|4[7]|5[0-27-9]|7[8]|8[2-47-8])\\d)\\d{7}$";
NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
if ([regextestcm evaluateWithObject:phoneNum]) {
return YES;
}
return NO;
}

是否是联通号码

/**
* 中国联通:China Unicom
* 13[0-2],145,15[5-6],17[5-6],18[5-6],170[4|7|8|9],171
*/
-(BOOL)isCUMobilePhone:(NSString *)phoneNum
{
NSString * CU = @"^1(70[07-9]|(3[0-2]|4[5]|5[5-6]|7[15-6]|8[5-6])\\d)\\d{7}$";
NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
if ([regextestcu evaluateWithObject:phoneNum]) {
return YES;
}
return NO;
}

是否是电信号码

/**
* 中国电信:China Telecom
* 133,1349,149,153,173,177,180,181,189,170[0-2]
*/
-(BOOL)isCTMobilePhone:(NSString *)phoneNum
{
NSString * CT = @"^1(34[9]|70[0-2]|(3[3]|4[9]|5[3]|7[37]|8[019])\\d)\\d{7}$";
NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
if ([regextestct evaluateWithObject:phoneNum]) {
return YES;
}
return NO;
}

邮箱验证

- (void)validationEmail:(NSString *)email {  

    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
if( [emailTest evaluateWithObject:email]){
NSLog(@"恭喜!您输入的邮箱验证合法");
}else{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入正确的邮箱" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil nil];
[alert show]; }
}

将手机号中特定位置替换为*号

- (NSString *)replaceStringWithAsterisk:(NSInteger)startLocation length:(NSInteger)length {
NSString *replaceStr = self;
for (NSInteger i = 0; i < length; i++) {
NSRange range = NSMakeRange(startLocation, 1);
replaceStr = [replaceStr stringByReplacingCharactersInRange:range withString:@"*"];
startLocation ++;
}
return replaceStr;
}

6~16位数字、字母、下划线组成的密码格式校验

-(BOOL)checkPsw:(NSString *)pswStr
{
NSString * pattern = @"^[A-Za-z0-9_]{6,16}$";
// NSString *condition =@"^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9]{6,16}";
NSPredicate * pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",pattern];
return [pred evaluateWithObject:pswStr];
}
//判断是否为整形:

+ (BOOL)isPureInt:(NSString*)string{
NSScanner* scan = [NSScanner scannerWithString:string];
int val;
return[scan scanInt:&val] && [scan isAtEnd];
} //判断是否为浮点形: + (BOOL)isPureFloat:(NSString*)string{
NSScanner* scan = [NSScanner scannerWithString:string];
float val;
return[scan scanFloat:&val] && [scan isAtEnd];
}

//身份证验证

#pragma mark ———————————————————— 判断身份证号
+ (BOOL) validateIdentityCard: (NSString *)value
{ value = [value stringByReplacingOccurrencesOfString:@" " withString:@""];
if (value.length != 18) {
return NO;
}
NSArray* codeArray = [NSArray arrayWithObjects:@"7",@"9",@"10",@"5",@"8",@"4",@"2",@"1",@"6",@"3",@"7",@"9",@"10",@"5",@"8",@"4",@"2", nil];
NSDictionary* checkCodeDic = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"1",@"0",@"X",@"9",@"8",@"7",@"6",@"5",@"4",@"3",@"2", nil] forKeys:[NSArray arrayWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil]]; NSScanner* scan = [NSScanner scannerWithString:[value substringToIndex:17]]; int val;
BOOL isNum = [scan scanInt:&val] && [scan isAtEnd];
if (!isNum) {
return NO;
}
int sumValue = 0; for (int i =0; i<17; i++) {
sumValue+=[[value substringWithRange:NSMakeRange(i , 1) ] intValue]* [[codeArray objectAtIndex:i] intValue];
} NSString* strlast = [checkCodeDic objectForKey:[NSString stringWithFormat:@"%d",sumValue%11]]; if ([strlast isEqualToString: [[value substringWithRange:NSMakeRange(17, 1)]uppercaseString]]) {
return YES;
}
return NO; }

iOS邮箱、手机号等常用验证功能 判断字符串是否int float的更多相关文章

  1. iOS开发——手机号,密码,邮箱,身份证号,中文判断

    目前这些方面的判断主要是用了正则表达式 手机号的判断,目前主要是长度.均是数字,支持的号段由于第三方通讯比如京东通讯,小米通讯等支持的号段挺多, 有171,170,135,147等等,所以号段限制简单 ...

  2. iOS常用小功能

    CHENYILONG Blog 常用小功能 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong  ...

  3. ValidateUtil常用验证工具类,如手机、密码、邮箱等

    package cn.com.ssk.util.utils; import java.util.regex.Pattern; import org.apache.commons.lang3.Strin ...

  4. iOS 常用小功能 总结

    常用小功能 iOS中的很多小功能都是非常简单的,几行代码就搞定了,比如打电话.打开网址.发邮件.发短信等 打电话 方法一(不被采用): 拨号之前会弹框询问用户是否拨号,拨完后能自动回到原应用 NSUR ...

  5. PHP实现邮箱验证码验证功能

    *文章来源:https://blog.egsec.cn/archives/623  (我的主站) *本文将主要说明:PHP实现邮箱验证码验证功能,通过注册或登录向用户发送身份确认验证码,并通过判断输入 ...

  6. javamail实现邮箱验证功能

    javamail是基于SMTP协议和POP3协议的邮件发送与接收系统,在用户注册与登陆的过程中,常需要用到邮箱验证功能,下面是基于javamail的一个简单实现 用户注册后通过servlet得到邮箱地 ...

  7. discuz3.2x增加邮箱验证功能

    为防止垃圾用户多次注册,为disczu增加邮箱验证功能. 大致分为二步: 1.申请邮箱,这里推荐使用腾讯免费企业邮箱:https://exmail.qq.com/portal/introducefre ...

  8. iOS 网易彩票-6设置模块三(常用小功能)

    该篇文章中,用到很多iOS开发过程中常用的小功能,当前只是将这些功能集成到网易彩票的设置中.iOS-常用小功能介绍,请参考我的另一篇文章: iOS 常用小功能 总结:http://www.cnblog ...

  9. thinkPHP 表单自动验证功能

    昨天晚上我们老大叫我弄表单自动验证功能,愁了半天借鉴了好多官网的知识,才出来,诶,总之分享一下我自己的成果吧! thinkphp 在Model基类为我们定义了自动验证的函数和正则表达式,我们只需要在对 ...

随机推荐

  1. Oracle RAC:使用 NFS 共享存储时的 mount 选项 总结

    oracle rac 使用nfs作为共享存储时,mount的选项有 要求,不能随便设置 grid的要求:      rw,bg,hard,nointr,rsize=32768,wsize=32768, ...

  2. 【matlab】error:试图访问 im2(1,1211);由于 size(im2)=[675,1210],索引超出范围。

    试图访问 im2(1,1211):由于 size(im2)=[675,1210],索引超出范围. 出错 dect (line 14) if abs((im2(i,j))-(im1(i,j)))> ...

  3. python3.0与python2.0有哪些不同

    python3的语法跟python2哪里变了. 1. python3中1/2终于等于0.5 了 2. print "Hello World"变成了print("Hello ...

  4. vue 组件库

    iView https://www.iviewui.com/ Radon UI https://luojilab.github.io/radon-ui/#!/ Element http://eleme ...

  5. 【jdk源码学习】HashMap

    package com.emsn.crazyjdk.java.util; /** * “人”类,重写了equals和hashcode方法...,以id来区分不同的人,你懂的... * * @autho ...

  6. LeetCode——Search for a Range

    Description: Given a sorted array of integers, find the starting and ending position of a given targ ...

  7. javascript关于链接的一些用法

    (1)javascript:openURL() http://www.kpdown.com/search?name=Ben Nadel 此URL后边有一个name参数,只不过参数的值竟然带了空格,这样 ...

  8. SNMP信息泄露漏洞

    SNMP协议简介 名称:SNMP(Simple Network Management Protocol)简单网络管理协议 端口:161 协议:UDP 用途:SNMP代理者以变量呈现管理资料.管理系统透 ...

  9. 关于移动端rem 布局的一些总结

    1.rem是什么? rem(font size of the root element)是指相对于根元素的字体大小的单位 2.为什么web app要使用rem? 实现强大的屏幕适配布局(淘宝,腾讯,网 ...

  10. Mysql explain执行计划

    EXPLAIN(小写explain)显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. EXPLAIN + sql语句可以查看mysql的执行 ...