zoukankan      html  css  js  c++  java
  • uitextfield 只能输入数字,正则表达式

     1、定义一个要保留的常量 #define NUMBERS @"0123456789.\n"

     2、实现delegate

    3、

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

    {

        NSCharacterSet *cs;

        cs = [[NSCharacterSetcharacterSetWithCharactersInString: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;

        }

        else if (textField.text.length>10)

        {

            

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

                                                            message:@"输入格式错误"

                                                           delegate:nil

                                                  cancelButtonTitle:@"确定"

                                                  otherButtonTitles:nil];

            

            [alert show];

            return NO;

        }

        

        returnYES;

    }

  • 相关阅读:
    Nginx日志
    Aapche日志
    IIS日志
    pikachu 不安全的url重定向
    pikachu php反序列化、XXE、SSRF
    pikachu 越权漏洞
    pikachu 不安全的文件下载和上传
    pikachu Files Inclusion(文件包含漏洞)
    pikachu RCE部分(远程命令、代码执行漏洞)
    pikachu SQL部分(下)
  • 原文地址:https://www.cnblogs.com/sgdkg/p/2825990.html
Copyright © 2011-2022 走看看