• iOS 限制只能输入数字(字母)


    #define NUMBERS @"0123456789"

    #define ENGLISH @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefjhigklmnopqrstuvwxyz"

    - (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string

    {

        NSCharacterSet*cs;

        cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS] invertedSet];

        NSString*filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];

        BOOL basicTest = [string isEqualToString:filtered];

        if(!basicTest) {

            

            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示"

                                                           message:@"请输入数字"

                                                          delegate:nil

                                                 cancelButtonTitle:@"确定"

                                                 otherButtonTitles:nil];

            

            [alert show];

            return NO;

            

        }

        return YES;

    }

  • 相关阅读:
    TWaver HTML5 (2D)--基本概念
    浏览器编码的函数简介escape(),encodeURI(),encodeURIComponent()
    pom.xml
    注解式控制器简介
    Controller接口
    WebContentGenerator
    Controller简介
    DispatcherServlet中使用的特殊的Bean
    DispatcherServlet默认配置
    DispatcherServlet
  • 原文地址:https://www.cnblogs.com/hongyan1314/p/5694935.html
Copyright © 2020-2023  润新知