Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate UITextField

I have a UITextField in my app, created in IB. I need to validate the same. i.e. it should be a number between 2 and 20

What is the best possible way of doing the validation; through code OR can this be completely controlled from the IB ?

Please let me know the ways to validate the field.

like image 500
copenndthagen Avatar asked Dec 28 '22 01:12

copenndthagen


1 Answers

You can't validate that from Interface Builder.

Try something like this. After textField initialization, put a Value Changed handler like this:

[textField 
    addTarget:self 
    action:@selector(validateField:) 
    forControlEvents:UIControlEventEditingChanged
];

Then write a message like this:

- validateField:(id)sender
{
    // put validation code here
}
like image 70
Pablo Santa Cruz Avatar answered Jan 11 '23 21:01

Pablo Santa Cruz