且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用户输入时如何检查 textFiled 输入字符串

更新时间:2023-11-28 23:29:46

按照以下步骤操作,可能会有所帮助:

Follow below steps, may it help:

  1. delegatetag 设置为 UIAlertController 文本字段.

  1. Set delegate and tag to UIAlertController textfields.

现在使用 UITextField 委托方法 shouldChangeCharactersInRange 在键入时验证文本或使用 textFieldDidEndEditing 在文本字段结束编辑后进行检查.检查使用它的标签来区分 textFields.

Now use UITextField delegate method shouldChangeCharactersInRange to validate text while typing OR use textFieldDidEndEditing to check after textfield end editing . Check using it's tag to differentiate between textFields.

喜欢

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

if(textField.tag==TxtNameTag){

   //Validate Name textField
}
//Same way for other textFields


    return YES; 
}

OR 使用 textFieldDidEndEditing 在 textField 结束编辑时进行验证.

OR Use textFieldDidEndEditing to validate while textField end editing.