Validate textfields in iOS

Hello,
We need to give validations to text fields in iOS such as zip code,only accept alphabets,etc.
How it can be achieve?
Do we need to use delegate and declares?
Please explain in detail as we don’t know about how to use declares and delegates in xojo.

Use the TextField’s mask property, it’s available on the Inspector palette in the Behaviour section…

Sorry… I missed the iOS part, perhaps you should have posted to the iOS forums instead of the General forums… Looks like you might have to roll your own (which is what you are kind of asking) or do a search to see if someone already has something written…

Maybe someone can convert the code from this page http://www.tempel.org/UITextFieldValidation into something that can be used in Xojo…

We currently use the JKRegEx class from iOS Kit: https://github.com/kingj5/iOSKit

It doesn’t limit the user from typing something, but can help validating if the input is correct.

Try to remove the characters from textfield you dont want.
On textchange event you can test the last entered character - right(text,1) - if its a character you want to remove or not. You can filter your textfield with ascii table.

Using iOS is not the same as using a desktop computer.

You can bring up specific keyboards (like numbers only) however you should not do more than that to the user. Please follow Jrmie’s advice and validate after input, not during.

Indeed iOS or Android do not work at all like Desktop. Better apply a format when the Textfield loses focus. I use my iOSWrapper to check if the TextField has focus.

https://github.com/Mitchboo/XojoiOSWrapper

This works on an iPhone, but on an iPad you still get a full keyboard. I use Roland’s method of checking for each character entered.

Well, you’re doing it wrong. Using iOS is not like using a Desktop computer. Your user has no idea why it won’t accept the letter they tried, and there’s no feedback system in iOS to tell them why.

You should validate the field when the user leaves or is done, and notify them in some way that the field is not acceptable. This is what they expect, and to provide a good user experience you must respect that.

In my case where I do this the user does know that it’s a numeric-only field. But I accept your point.

We have used JKRegEx class from iOS Kit to validate if user input is correct or not.
We have checked on Text change event of Textfield,but it seems to be not good as it fires many times while user typing.
We need to check it when Textfield loses focus.
Can we use timer to raise lost focus event by checking isFirstResponder method for each and every Textfield?
How can it be achieved ?

[quote=302376:@Nikita Chitnis]
Can we use timer to raise lost focus event by checking isFirstResponder method for each and every Textfield?
How can it be achieved ?[/quote]
I put a label on a textfield, if the user clicks on the the label, i hide the label and set the focus on the textfield. Starts the timer.
mouseup event on label: start timer, textfield.setfocus, hidelabel
Inn the timer which ticks every x miliseconds:

if controlname.isFirstResponder=false then //lost focus so i will format the text, alert the user timer.mode=xojo.core.timer.modes.off showlabel end if

I hope this helps.

200-500 Millisecond is probably enough for the timer.