• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Filtering textfield input on iOS

Engaged ,
Jun 20, 2018 Jun 20, 2018

Copy link to clipboard

Copied

Hi,

I need to ask people to enter a 6-digit number (an integer) in a textfield, with only characters ranging from 0 to 9.

I use a regular TextField, with a DECIMAL type soft keyboard. On the CHANGE event, I check the contents of the TextField, and if I detect a non-digit character, I remove it from the TextField.text string, then re-assign the cleaned-up string to the TextField. On Windows, it works perfectly fine.

But on iOS, I get a weird behavior. If I type a comma (which is present on the decimal soft keyboard on iOS), my code tries to clean the TextField string, and when I assign it back to the TextField, the comma is still there, and the text of the TextField is fully selected (as if I had made a long press on the text, and selected it all). So there is a double issue: the cleaned-up string is not reassigned properly to the TextField content, and all the content of the TextField is selected, so the next key press on the soft keyboard will erase everything.

Do you know if there is some way to filter the contents of a TextField on iOS while you are typing, to limit the range of characters you can enter?

Thank you very much!

TOPICS
Development

Views

374

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Jun 20, 2018 Jun 20, 2018

Hey,

you should be able to use the .restrict field on the TextField to limit the input characters to the characters you set. E.g.

tf.restrict = "0123456789";

should work in your case.

Votes

Translate

Translate
Advocate ,
Jun 20, 2018 Jun 20, 2018

Copy link to clipboard

Copied

Hey,

you should be able to use the .restrict field on the TextField to limit the input characters to the characters you set. E.g.

tf.restrict = "0123456789";

should work in your case.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 20, 2018 Jun 20, 2018

Copy link to clipboard

Copied

Oh, awesome! Thank you so much for your quick reply. I'm always amazed at the power of AIR. It indeed works, and now I can't type a comma, so this is great.

However, I also have to limit the number to 6 digits max. In my code, I simply check the TextField.text length, and if it is greater then 6, I only reassign a substring to the TextField. However, as explained above, reassigning a value to a TextField causes this strange behavior of selecting the whole text instead. I don't think there is a native TextField property that limits the numbers of characters, right?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 20, 2018 Jun 20, 2018

Copy link to clipboard

Copied

Well, how hard would it be to check that It's .maxChars

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 20, 2018 Jun 20, 2018

Copy link to clipboard

Copied

LATEST

Okay, now I feel ashamed lol. My only poor excuse is that I'm not on a computer right now, and checking the AS3 docs were not very easy for me. Thank you so much for holding my hand on that one!

Cheers!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines