zoukankan      html  css  js  c++  java
  • 正则表达式使用和键盘监听

    一、正则表达式

    使用环境很多,但经常会在用户名和密码 判断

    了解更多可以查看网址内容,比如下面这个一般都能应付了:http://www.admin10000.com/document/5944.html 

    例子:

    NSString *regex = @"^[a-z0-9A-Zu4e00-u9fa5]+";

        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];

        NSString *str = @"舞舞舞*";

        if ([predicate evaluateWithObject:str]) {

            NSLog(@"match1");

        }else{

            NSLog(@"===");

        }

       

    二、 一般的使用场景

    监听UITextField、UITextView 等等

    - (void)viewDidLoad {

        [super viewDidLoad];

    // 监听textfiled 和 keyboard

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textfiledChangeValue:) name:UITextFieldTextDidChangeNotification object:self.textfiled];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeKeyboardHeight:) name:UIKeyboardWillShowNotification object:nil];

    }

    // textfiled

     - (void)textfiledChangeValue:(NSNotification *)notification {

        UITextField *filed = notification.object;

        NSString *str = filed.text;

        NSString *language = [filed.textInputMode primaryLanguage];

        if ([language isEqualToString:@"zh-Hans"]) {   //  第一语言 zh-Hans 中文

            NSString *regex = @"^[a-zA-Z0-9u4e00-u9fa5]+";

            NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];

            BOOL isMatch = [predicate evaluateWithObject:str];

         

            if (isMatch) {

                NSLog(@"it is beyond of limit number");

            }else {

                NSLog(@"it can't containt unexpected symbol");

            }

        }

    }

     

    - (void)changeKeyboardHeight:(NSNotification *)notificaton {

     

        CGFloat keyboardHeight = [notificaton.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;

        self.marginTop.constant =  - 100;

    }

  • 相关阅读:
    2021.1.28 个人rating赛补题报告
    2021.1.23 个人rating赛补题报告
    2021.1.23 个人rating赛补题报告
    2020.12.14 个人训练赛补题报告
    2020.11.28 2020团体程序设计天梯赛补题报告
    2020.12.3 Codeforces Beta Round #73(Div2)补题报告
    Xhorse VVDI Prog V5.0.6 is Ready for BCM2 Adapter
    Program 2021 Ford Bronco All Keys Lost using VVDI Key Tool Plus
    Xhorse VVDI Prog V5.0.4 Software Update in July 2021
    How to use Xhorse VVDI2 to Exchange BMW FEM/BDC Module?
  • 原文地址:https://www.cnblogs.com/tony0571/p/5436648.html
Copyright © 2011-2022 走看看