IPhone simple phone number validation

后端 未结 3 451
别跟我提以往
别跟我提以往 2020-12-09 06:56

I find all kinds of phone number validations on stackoverflow for the iphone but none seem to validate they just seem to change the format. example Phone number formatting.

3条回答
  •  春和景丽
    2020-12-09 07:23

    Using this validation you can only enter 10 numbers. You can change it's length according to your requirement.

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    
     BOOL valid = [[NSPredicate predicateWithFormat:@"SELF MATCHES %@", REGEX_FOR_INTEGERS] evaluateWithObject:_textFieldValidate.text];
    
    
    
           if(valid){
               if(range.length + range.location > textField.text.length)
               {
                   return NO;
               }
    
               NSUInteger newLength = [textField.text length] + [string length] - range.length;
               return newLength <= 10;
    
    
    }
    
    
    return YES;
    
    }
    

    Hope this will help you.

提交回复
热议问题