北京邮政编码码的作用(5字)

『徐家汇花园的邮编』相关搜索
(C) 列表网&京ICP证100421号&京ICP备号-1&琼公网安备08http://blog.csdn.net/dyllove98/article/details/8635079
IdentifierValidator.h
//& IdentifierValidator.h
//& 银行卡校验
//& Created by 杨梦晓 on 14-9-9.
//& Copyright (c) 2014年 杨梦晓. All rights reserved.
#import &Foundation/Foundation.h&
typedefenum
& & IdentifierTypeKnown = 0,
& & IdentifierTypeZipCode,& & & //1
& & IdentifierTypeEmail,& & & & //2
& & IdentifierTypePhone,& & & & //3
& & IdentifierTypeUnicomPhone,& //4
& & IdentifierTypeQQ, & & & & & //5
& & IdentifierTypeNumber, & & & //6
& & IdentifierTypeString, & & & //7
& & IdentifierTypeIdentifier, & //8
& & IdentifierTypePassort,& & & //9
& & IdentifierTypeCreditNumber, //10
& & IdentifierTypeBirthday, & & //11
}IdentifierT
@interface IdentifierValidator : NSObject
+ (BOOL) isValid:(IdentifierType) type value:(NSString*)
-----------------------------------------------
IdentifierValidator.m
//& IdentifierValidator.m
//& 银行卡校验
//& Created by 杨梦晓 on 14-9-9.
//& Copyright (c) 2014年 杨梦晓. All rights reserved.
#import "IdentifierValidator.h"
#import "NSString+ITTAdditions.h"
int getIndex (char ch);
BOOL isNumber (char ch);
int getIndex (char ch) {
& & if ((ch &= '0'&& ch &= '9')||(ch &= 'a'&& ch &= 'z')||
& & & & (ch &= 'A' && ch &= 'Z')|| ch == '_') {
& & & & return 0;
& & if (ch == '@') {
& & & & return 1;
& & if (ch == '.') {
& & & & return 2;
& & return -1;
BOOL isNumber (char ch)
& & if (!(ch &= '0' && ch &= '9')) {
& & & & returnFALSE;
& & returnTRUE;
@implementation IdentifierValidator
#pragma mark - 校验邮编
+ (BOOL) isValidZipcode:(NSString*)value
& & const char *cvalue = [value UTF8String];
& & int len = strlen(cvalue);
& & if (len != 6) {
& & & & returnFALSE;
& & for (int i = 0; i & i++)
& & & & if (!(cvalue[i] &= '0' && cvalue[i] &= '9'))
& & & & & & return FALSE;
& & returnTRUE;
#pragma mark - 校验email
+ (BOOL) validateEmail:(NSString *)candidate
& & NSArray *array = [candidate componentsSeparatedByString:@"."];
& & if ([array count] &= 4) {
& & & & returnFALSE;
& & 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:candidate];
+ (BOOL) isValidEmail:(NSString*)value {
& & static int state[5][3] = {
& & & & {1, -1, -1},
& & & & {1,& 2, -1},
& & & & {3, -1, -1},
& & & & {3, -1, 4},
& & & & {4, -1, -1}
& & BOOL valid = TRUE;
& & const char *cvalue = [value UTF8String];
& & int currentState = 0;
& & int len = strlen(cvalue);
& & for (int i = 0; i & len && i++) {
& & & & index = getIndex(cvalue[i]);
& & & & if (index & 0) {
& & & & & & valid = FALSE;
& & & & else {
& & & & & & currentState = state[currentState][index];
& & & & & & if (currentState & 0) {
& & & & & & & & valid = FALSE;
& & & & & & }
& & //end state is invalid
& & if (currentState != 4) {
& & & & valid = FALSE;
& & return
#pragma mark - 校验数字
+ (BOOL) isValidNumber:(NSString*)value{
& & const char *cvalue = [value UTF8String];
& & int len = strlen(cvalue);
& & for (int i = 0; i & i++) {
& & & & if(!isNumber(cvalue[i])){
& & & & & & return FALSE;
& & returnTRUE;
#pragma mark - 校验手机号
+ (BOOL) isValidPhone:(NSString*)value {
& & const char *cvalue = [value UTF8String];
& & int len = strlen(cvalue);
& & if (len != 11) {
& & & & returnFALSE;
& & if (![IdentifierValidatorisValidNumber:value])
& & & & returnFALSE;
& & NSString *preString = [[NSString stringWithFormat:@"%@",value] substringToIndex:2];
& & if ([preString isEqualToString:@"13"] ||
& & & & [preString isEqualToString: @"15"] ||
& & & & [preString isEqualToString: @"18"])
& & & & return TRUE;
& & & & returnFALSE;
& & returnTRUE;
#pragma mark - 校验字符串
+ (BOOL) isValidString:(NSString*)value
& & return value && [value length];
const int factor[] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };//加权因子
const int checktable[] = { 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 };//校验值对应表
#pragma mark - 校验身份证号
+ (BOOL) isValidIdentifier:(NSString*)value
& & const int LENGTH = 18;
& & const char *str = [[value lowercaseString] UTF8String];
& & NSInteger
& & NSInteger length = strlen(str);
& & BOOL result = TRUE;
&& & * identifier length is invalid
& & if (15 != length && LENGTH != length)
& & & & result = FALSE;
& & & & for (i = 1; i & length - 1; i++)
& & & & & & if(!(str[i] &= '0' && str[i] &= '9'))
& & & & & & {
& & & & & & & & result = FALSE;
& & & & & & & & break;
& & & & & & }
& & & & if (result)
& & & & & & if(LENGTH == length)
& & & & & & {
& & & & & & & & if (!((str[i] &= '0' && str[i] &= '9')||str[i] == 'X'||str[i] == 'x'))
& & & & & & & & {
& & & & & & & & & & result = FALSE;
& & & & & & & & }
& & & & & & }
& & & & /*
&& & & & * check sum for second generation identifier
&& & & & */
& & & & if (result && length == LENGTH)
& & & & & & int
& & & & & & int *ids = malloc(sizeof(int)*LENGTH);
& & & & & & for (i = 0; i & LENGTH; i++)
& & & & & & {
& & & & & & & & ids[i] = str[i] - 48;
& & & & & & }
& & & & & & int checksum = 0;
& & & & & & for (i = 0; i & LENGTH - 1; i ++ )
& & & & & & {
& & & & & & & & checksum += ids[i] * factor[i];
& & & & & & }
& & & & & & if (ids[17] == checktable[checksum%11]||
& & & & & & & & (str[17] == 'x' && checktable[checksum % 11] == 10))
& & & & & & {
& & & & & & & & result& = TRUE;
& & & & & & }
& & & & & & else
& & & & & & {
& & & & & & & & result& = FALSE;
& & & & & & }
& & & & & & free(ids);
& & & & & & ids = NULL;
& & return
#pragma mark - 校验护照
+ (BOOL) isValidPassport:(NSString*)value
& & const char *str = [value UTF8String];
& & char first = str[0];
& & NSInteger length = strlen(str);
& & if (!(first == 'P' || first == 'G'))
& & & & returnFALSE;
& & if (first == 'P')
& & & & if (length != 8)
& & & & & & return FALSE;
& & if (first == 'G')
& & & & if (length != 9)
& & & & & & return FALSE;
& & BOOL result = TRUE;
& & for (NSInteger i = 1; i & i++)
& & & & if (!(str[i] &= '0' && str[i] &= '9'))
& & & & & & result = FALSE;
& & & & & & break;
& & return
&* 常用信用卡卡号规则
&* Issuer Identifier& Card Number& & & & & & & & & & & & & & Length
&* Diner's Club & & & 300xxx-305xxx, 3095xx, 36xxxx, 38xxxx& 14
&* American Express & 34xxxx, 37xxxx & & & & & & & & & & & & 15
&* VISA & & & & & & & 4xxxxx & & & & & & & & & & & & & & & & 13, 16
&* MasterCard & & & & 51xxxx-55xxxx& & & & & & & & & & & & & 16
&* JCB& & & & & & & & 3528xx-358xxx& & & & & & & & & & & & & 16
&* Discover & & & & & 6011xx & & & & & & & & & & & & & & & & 16
&* 银联& & & & & & & & 925& & & & & & & & & & & & & 16
&* 信用卡号验证基本算法:
&* 偶数位卡号奇数位上数字*2,奇数位卡号偶数位上数字*2。
&* 大于10的位数减9。
&* 全部数字加起来。
&* 结果不是10的倍数的卡号非法。
&* prefrences link:
#pragma mark - 校验信用卡号
+ (BOOL) isValidCreditNumber:(NSString*)value
& & BOOL result = TRUE;
& & NSInteger length = [value length];
& & if (length &= 13)
& & & & result = [IdentifierValidator isValidNumber:value];
& & & & if (result)
& & & & & & NSInteger twoDigitBeginValue = [[value substringWithRange:NSMakeRange(0, 2)] integerValue];
& & & & & & NSInteger threeDigitBeginValue = [[value substringWithRange:NSMakeRange(0, 3)] integerValue];
& & & & & & NSInteger fourDigitBeginValue = [[value substringWithRange:NSMakeRange(0, 4)] integerValue];
& & & & & & //Diner's Club
& & & & & & if (((threeDigitBeginValue &= 300 && threeDigitBeginValue &= 305)||
&& & & & & & & & fourDigitBeginValue == 3095||twoDigitBeginValue==36||twoDigitBeginValue==38) && (14 != length))
& & & & & & {
& & & & & & & & result = FALSE;
& & & & & & }
& & & & & & //VISA
& & & & & & else if([value isStartWithString:@"4"] && !(13 == length||16 == length))
& & & & & & {
& & & & & & & & result = FALSE;
& & & & & & }
& & & & & & //MasterCard
& & & & & & else if((twoDigitBeginValue &= 51||twoDigitBeginValue &= 55) && (16 != length))
& & & & & & {
& & & & & & & & result = FALSE;
& & & & & & }
& & & & & & //American Express
& & & & & & else if(([value isStartWithString:@"34"]||[value isStartWithString:@"37"]) && (15 != length))
& & & & & & {
& & & & & & & & result = FALSE;
& & & & & & }
& & & & & & //Discover
& & & & & & else if([value isStartWithString:@"6011"] && (16 != length))
& & & & & & {
& & & & & & & & result = FALSE;
& & & & & & }
& & & & & & else
& & & & & & {
& & & & & & & & NSInteger begin = [[value substringWithRange:NSMakeRange(0, 6)] integerValue];
& & & & & & & & //CUP
& & & & & & & & if ((begin &= 622126 && begin &= 622925) && (16 != length))
& & & & & & & & {
& & & & & & & & & & result = FALSE;
& & & & & & & & }
& & & & & & & & //other
& & & & & & & & else
& & & & & & & & {
& & & & & & & & & & result = TRUE;
& & & & & & & & }
& & & & & & }
& & & & if (result)
& & & & & & NSInteger digitV
& & & & & & NSInteger checkSum = 0;
& & & & & & NSInteger index = 0;
& & & & & & NSInteger leftI
& & & & & & //even length, odd index
& & & & & & if (0 == length%2)
& & & & & & {
& & & & & & & & index = 0;
& & & & & & & & leftIndex = 1;
& & & & & & }
& & & & & & //odd length, even index
& & & & & & else
& & & & & & {
& & & & & & & & index = 1;
& & & & & & & & leftIndex = 0;
& & & & & & }
& & & & & & while (index & length)
& & & & & & {
& & & & & & & & digitValue = [[value substringWithRange:NSMakeRange(index, 1)] integerValue];
& & & & & & & & digitValue = digitValue*2;
& & & & & & & & if (digitValue &= 10)
& & & & & & & & {
& & & & & & & & & & checkSum += digitValue/10 + digitValue%10;
& & & & & & & & }
& & & & & & & & else
& & & & & & & & {
& & & & & & & & & & checkSum += digitV
& & & & & & & & }
& & & & & & & & digitValue = [[value substringWithRange:NSMakeRange(leftIndex, 1)] integerValue];
& & & & & & & & checkSum += digitV
& & & & & & & & index += 2;
& & & & & & & & leftIndex += 2;
& & & & & & }
& & & & & & result = (0 == checkSum%10) ? TRUE:FALSE;
& & & & result = FALSE;
& & return
#pragma mark - 校验生日
+ (BOOL) isValidBirthday:(NSString*)birthday
& & BOOL result = FALSE;
& & if (birthday && 8 == [birthday length])
& & & & NSDateFormatter *formatter = [[NSDateFormatteralloc] init];
& & & & [formatter setDateFormat:@"yyyyMMdd"];
& & & & NSDate *date = [formatter dateFromString:birthday];
& & & & if (date)
& & & & & & result = TRUE;
& & return
#pragma mark - 校验联通号
+ (BOOL) isChinaUnicomPhoneNumber:(NSString*) phonenumber
&& & * 手机号码
&& & * 移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
&& & * 联通:130,131,132,152,155,156,185,186
&& & * 电信:133,,189
& & //& & NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
&& & 10 & & & & * 中国移动:China Mobile
&& & 11 & & & & * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
&& & 12 & & & & */
& & //& & NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
& & //& & /**
& & // & & 15 & & & & * 中国联通:China Unicom
& & // & & 16 & & & & * 130,131,132,152,155,156,185,186
& & // & & 17 & & & & */
& & NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
& & //& & /**
& & // & & 20 & & & & * 中国电信:China Telecom
& & // & & 21 & & & & * 133,,189
& & // & & 22 & & & & */
& & //& & NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
& & //& & /**
& & // & & 25 & & & & * 大陆地区固话及小灵通
& & // & & 26 & & & & * 区号:010,020,021,022,023,024,025,027,028,029
& & // & & 27 & & & & * 号码:七位或八位
& & // & & 28 & & & & */
& & //& & NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
& & //& & NSString * PHS1 = @"^0(10|2[0-5789]|\\d{3}-)\\d{7,8}$";
& & //& & NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
& & //& & NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
& & NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
& & //& & NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
& & //& & NSPredicate *regextestphs = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", PHS];
& & //& & NSPredicate *regextestphs1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", PHS1];
& & if (//([regextestmobile evaluateWithObject:phonenumber] == YES)||
& & & & //& & & & ([regextestcm evaluateWithObject:phonenumber] == YES)||
& & & & //& & & & ([regextestct evaluateWithObject:phonenumber] == YES)||
& & & & ([regextestcu evaluateWithObject:phonenumber] == YES)
& & & & //& & & & || ([regextestphs evaluateWithObject:phonenumber] == YES)
& & & & //& & & & || ([regextestphs1 evaluateWithObject:phonenumber] == YES)
& & & & return YES;
& & & & return NO;
//+ (BOOL) isChinaUnicomPhoneNumber:(NSString*) phoneNumber
//& & BOOL unicom = TRUE;
//& & NSString *mobileNumFormat13 = @"[1]{1}[3]{1}[4-9]{1}[0-9]{8}";
//& & NSString *mobileNumFormat14 = @"[1]{1}[4]{1}[7]{1}[0-9]{8}";
//& & NSString *mobileNumFormat15 = @"[1]{1}[5]{1}[}[0-9]{8}";
//& & NSString *mobileNumFormat18 = @"[1]{1}[8]{1}[-9]{8}";
//& & NSPredicate *predicate13 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",mobileNumFormat13];
//& & NSPredicate *predicate14 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",mobileNumFormat14];
//& & NSPredicate *predicate15 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",mobileNumFormat15];
//& & NSPredicate *predicate18 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",mobileNumFormat18];
//& & if ([predicate13 evaluateWithObject:phoneNumber] ||
//& & & & [predicate14 evaluateWithObject:phoneNumber] ||
//& & & & [predicate15 evaluateWithObject:phoneNumber] ||
//& & & & [predicate18 evaluateWithObject:phoneNumber])
//& & & & unicom = FALSE;
+ (BOOL) isValid:(IdentifierType) type value:(NSString*) value
& & if (!value ||[[value stringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceCharacterSet]] isEqualToString:@""]) {
& & & & returnFALSE;
& & BOOL result = TRUE;
& & switch (type)
& & & & caseIdentifierTypeZipCode:
& & & & & & result = [IdentifierValidator isValidZipcode:value];
& & & & & & break;
& & & & caseIdentifierTypeEmail:
& & & & & & //& & & & & & result = [IdentifierValidator isValidEmail:value];
& & & & & & result = [IdentifierValidator validateEmail:value];
& & & & & & break;
& & & & caseIdentifierTypePhone:
& & & & & & result = [IdentifierValidator isValidPhone:value];
& & & & & & break;
& & & & caseIdentifierTypeUnicomPhone:
& & & & & & result = [IdentifierValidator isChinaUnicomPhoneNumber:value];
& & & & & & break;
& & & & caseIdentifierTypeQQ:
& & & & & & result = [IdentifierValidator isValidNumber:value];
& & & & & & break;
& & & & caseIdentifierTypeNumber:
& & & & & & result = [IdentifierValidator isValidNumber:value];
& & & & & & break;
& & & & caseIdentifierTypeString:
& & & & & & result = [IdentifierValidator isValidString:value];
& & & & & & break;
& & & & caseIdentifierTypeIdentifier:
& & & & & & result = [IdentifierValidator isValidIdentifier:value];
& & & & & & break;
& & & & caseIdentifierTypePassort:
& & & & & & result = [IdentifierValidator isValidPassport:value];
& & & & & & break;
& & & & caseIdentifierTypeCreditNumber:
& & & & & & result = [IdentifierValidator isValidCreditNumber:value];
& & & & & & break;
& & & & caseIdentifierTypeBirthday:
& & & & & & result = [IdentifierValidator isValidBirthday:value];
& & & & & & break;
& & & & default:
& & & & & & break;
& & return
-----------------------------------------------
NSString+ITTAdditions.h
//& NSString+ITTAdditions.h
//& 银行卡校验
//& Created by 杨梦晓 on 14-9-9.
//& Copyright (c) 2014年 杨梦晓. All rights reserved.
#import &Foundation/Foundation.h&
@interface NSString (ITTAdditions)
- (BOOL)isStartWithString:(NSString *)
-----------------------------------------------
NSString+ITTAdditions.m
//& NSString+ITTAdditions.m
//& 银行卡校验
//& Created by 杨梦晓 on 14-9-9.
//& Copyright (c) 2014年 杨梦晓. All rights reserved.
#import "NSString+ITTAdditions.h"
@implementation NSString (ITTAdditions)
- (BOOL)isStartWithString:(NSString *)string{
& & int temp = [string intValue];
& & switch (temp) {
& & & & case 4:
& & & & & & return NO;
& & & & & & break;
& & & & case 34:
& & & & & & return NO;
& & & & & & break;
& & & & case 37:
& & & & & & return NO;
& & & & & & break;
& & & & case 6011:
& & & & & & return NO;
& & & & & & break;
&& & & & & &
& & & & default:
& & & & & & break;
& & returnYES;
-----------------------------------------------
MXViewController.m
//& MXViewController.m
//& 信用卡校验
//& Created by 杨梦晓 on 14-9-9.
//& Copyright (c) 2014年 ___FULLUSERNAME___. All rights reserved.
#import "MXViewController.h"
#import "IdentifierValidator.h"
@interfaceMXViewController () &UITextFieldDelegate&
@property (weak, nonatomic) IBOutletUITextField *textF
@implementation MXViewController
- (void)viewDidLoad
& & [superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
- (void)textFieldDidEndEditing:(UITextField *)textField{
& & // 信用卡校验
& & if ([IdentifierValidatorisValid:IdentifierTypeCreditNumbervalue:textField.text]) {
& & & & NSLog(@"通过");
& & }else{
& & & & NSLog(@"不通过");
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
& & [[[UIApplicationsharedApplication] keyWindow] endEditing:YES];
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
& & NSString *text = [textField text];
& & NSCharacterSet *characterSet = [NSCharacterSetcharacterSetWithCharactersInString:@"\b"];
& & string = [string stringByReplacingOccurrencesOfString:@" "withString:@""];
& & if ([string rangeOfCharacterFromSet:[characterSet invertedSet]].location != NSNotFound) {
& & & & return NO;
& & text = [text stringByReplacingCharactersInRange:range withString:string];
& & text = [text stringByReplacingOccurrencesOfString:@" "withString:@""];
& & NSString *newString = @"";
& & while (text.length & 0) {
& & & & NSString *subString = [text substringToIndex:MIN(text.length, 4)];
& & & & newString = [newString stringByAppendingString:subString];
& & & & if (subString.length == 4) {
& & & & & & newString = [newString stringByAppendingString:@" "];
& & & & text = [text substringFromIndex:MIN(text.length, 4)];
& & newString = [newString stringByTrimmingCharactersInSet:[characterSet invertedSet]];
& & if (newString.length &= 24) {
& & & & return NO;
& & [textField setText:newString];
& & returnNO;
- (void)didReceiveMemoryWarning
& & [superdidReceiveMemoryWarning];
& & // Dispose of any resources that can be recreated.
阅读(...) 评论()北京甜水园街万科公园5号20号写字楼邮编多少_百度知道
北京甜水园街万科公园5号20号写字楼邮编多少
&nbsp.5&amp?iknowflg=1&l=17&<iframe map="iknow/i=1|-1|-1&s=s%26addr%3D0%26wd%3D%25E4%25B8%%25A7%%2585%25AC%25E5%259B%25AD%25E4%25BA%%258F%25B7%26c%3D131%26src%3D0&amp.18.99【具体地址】北京市 朝阳区&c=;万科公园5号20号写字楼【邮政编码】100026 &甜水园街 &nbsp,4828421&b=,望采纳;t=B_NORMAL_MAP&newmap=1&t=1" class="ikqb-map">希望对你有所帮助,4828608.html
来自团队:
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁这是个机器人猖狂的时代,请输一下验证码,证明咱是正常人~

我要回帖

更多关于 上海邮政编码 的文章

 

随机推荐