RegistVC.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. //
  2. // RegistVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 2017/9/26.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #import "RegistVC.h"
  9. #import "RegistTestVC.h"
  10. @interface RegistVC ()
  11. {
  12. UITextField *phoneField;
  13. UITextField *pswField;
  14. UITextField *pswAgainField;
  15. }
  16. @end
  17. @implementation RegistVC
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [self.view setBackgroundColor:[UIColor whiteColor]];
  21. self.title = @"注册账号";
  22. [self configNavigationBarDismissNav];
  23. UIImageView *imageV= [[UIImageView alloc] initWithFrame:kFrame];
  24. imageV.image = [UIImage imageNamed:@"login0.png"];
  25. [self.view addSubview:imageV];
  26. CGFloat y = 60;
  27. CGFloat h = 40;
  28. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, y, 85, h)];
  29. [label setText:@"手机号" Font:FontTitle TextColor:kTitleColor];
  30. [self.view addSubview:label];
  31. UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(110, y, kSize.width - 125, h)];
  32. textField.borderStyle = UITextBorderStyleNone;
  33. textField.placeholder = @"请输入手机号";
  34. textField.font = [UIFont scaleSize:FontTitle];
  35. textField.clearButtonMode = UITextFieldViewModeWhileEditing;
  36. textField.keyboardType = UIKeyboardTypeNumberPad;
  37. [self.view addSubview:textField];
  38. phoneField = textField;
  39. [textField addViewWithRect:CGRectMake(15, y+h, kSize.width - 30, 1.5)];
  40. y += h + 10;
  41. label = [[UILabel alloc] initWithFrame:CGRectMake(15, y, 85, h)];
  42. [label setText:@"密码" Font:FontTitle TextColor:kTitleColor];
  43. [self.view addSubview:label];
  44. textField = [[UITextField alloc] initWithFrame:CGRectMake(110, y, kSize.width - 125, h)];
  45. textField.borderStyle = UITextBorderStyleNone;
  46. textField.placeholder = @"6~20字符以内,字母或数字";
  47. textField.font = [UIFont scaleSize:FontTitle];
  48. textField.clearButtonMode = UITextFieldViewModeWhileEditing;
  49. textField.secureTextEntry = YES;
  50. textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
  51. [self.view addSubview:textField];
  52. pswField = textField;
  53. [textField addViewWithRect:CGRectMake(15, y+h, kSize.width - 30, 1.5)];
  54. y += h + 10;
  55. label = [[UILabel alloc] initWithFrame:CGRectMake(15, y, 85, h)];
  56. [label setText:@"确认密码" Font:FontTitle TextColor:kTitleColor];
  57. [self.view addSubview:label];
  58. textField = [[UITextField alloc] initWithFrame:CGRectMake(110, y, kSize.width - 125, h)];
  59. textField.borderStyle = UITextBorderStyleNone;
  60. textField.placeholder = @"请再次输入";
  61. textField.font = [UIFont scaleSize:FontTitle];
  62. textField.clearButtonMode = UITextFieldViewModeWhileEditing;
  63. textField.secureTextEntry = YES;
  64. textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
  65. [self.view addSubview:textField];
  66. pswAgainField = textField;
  67. [textField addViewWithRect:CGRectMake(15, y+h, kSize.width - 30, 1.5)];
  68. y += h + 50;
  69. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(15, y, kSize.width - 30, h)];
  70. btn.backgroundColor = defGreen;
  71. btn.layer.masksToBounds = YES;
  72. btn.layer.cornerRadius = 4;
  73. [btn setTitle:@"下一步" textColor:[UIColor whiteColor] font:FontTitle fotState:UIControlStateNormal];
  74. [btn target:self tag:1];
  75. [self.view addSubview:btn];
  76. }
  77. - (void)btnClick:(UIButton *)sender {
  78. [self.view endEditing:YES];
  79. if (phoneField.text.length < 1) {
  80. [self showMsgWithString:@"请输入手机号!"];
  81. return;
  82. }
  83. if (pswField.text.length < 1 || pswAgainField.text.length < 1) {
  84. [self showMsgWithString:@"请输入并确认密码!"];
  85. return;
  86. }
  87. if (![pswField.text isEqualToString:pswAgainField.text]) {
  88. [self showMsgWithString:@"两次密码输入不一致,请重试!"];
  89. pswField.text = @"";
  90. pswAgainField.text = @"";
  91. return;
  92. }
  93. NSString *regex = @"^[0-9A-Za-z]{6,20}$";
  94. NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
  95. BOOL result = [pred evaluateWithObject:pswField.text];
  96. if (!result) {
  97. [self showMsgWithString:@"请输入6~20字符以内的数字或字母密码!"];
  98. return;
  99. }
  100. if ([self isTooSimpleWithString:pswField.text]) {
  101. [self showMsgWithString:@"密码设置太简单,请重新设置!"];
  102. pswField.text = @"";
  103. pswAgainField.text = @"";
  104. return;
  105. }
  106. if (![Util connectedToNetWork]) {
  107. showMsgUnconnect();
  108. return;
  109. }
  110. //发送验证码
  111. RegistTestVC *vc = [[RegistTestVC alloc] init];
  112. vc.phoneString = phoneField.text;
  113. vc.passwordString = pswField.text;
  114. [self.navigationController pushViewController:vc animated:NO];
  115. }
  116. - (void)showMsgWithString:(NSString *)string {
  117. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:string delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  118. [alert show];
  119. }
  120. //判断是否是简单的叠字或者升降序列 是返回YES
  121. - (BOOL)isTooSimpleWithString:(NSString *)pswString {
  122. int differentInt = 100;
  123. for (int i = 1; i < pswString.length; i ++) {
  124. NSInteger number = [pswString characterAtIndex:i];
  125. NSInteger lastNumber = [pswString characterAtIndex:i - 1];
  126. // NSLog(@"---->>>>%d-%d = %d",number,lastNumber,differentInt);
  127. if (differentInt != number - lastNumber && differentInt != 100) {
  128. return NO;
  129. }else {
  130. differentInt = number - lastNumber;
  131. }
  132. }
  133. return YES;
  134. }
  135. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  136. [self.view endEditing:YES];
  137. }
  138. - (void)didReceiveMemoryWarning {
  139. [super didReceiveMemoryWarning];
  140. }
  141. @end