GithubHelp home page GithubHelp logo

jktextinputobserver's Introduction

JKTextInputObserver

监听UITextField和UITextView的输入,可能限定输入的长度和内容,比如限制11位数字(手机号码)

CocoaPods

platform :ios, '8.0'

source 'https://github.com/CocoaPods/Specs.git'

pod 'JKTextInputObserver', '~> 1.0.5'

Usage

#import <JKTextInputObserver/JKTextInputObserver.h>
@interface AccountInputView () <UITextFieldDelegate,JKTextInputObserverDelegate>

@property (nonatomic, strong) JKTextInputObserver * phoneObserver;
@property (nonatomic, strong) JKTextInputObserver * captchObserver;

@end


phoneTF.delegate = self;
_phoneObserver = [[JKTextInputObserver alloc] initWithTextField:phoneTF];
_phoneObserver.maximumLength = 11;            // 最多11位字符
_phoneObserver.matchRegular = @"^[0-9]\\d*$"; // 只能输入数字
_phoneObserver.delegate = self;



/// 必须实现此协议方法,以实现字符过滤
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (textField == self.phoneObserver.textField) {
        return [self.phoneObserver jk_textField:textField range:range shouldChangeString:string];
    }
    return [self.captchObserver jk_textField:textField range:range shouldChangeString:string];
}

常用正则

数字			^[0-9]\\d*$    
英文+数字		^[A-Za-z0-9]+$
中英文+数字		^[a-zA-Z\u4E00-\u9FA5\\u0030-\\u0039-➒]+$

jktextinputobserver's People

Contributors

xifenglang avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.