Skip to main content
Inspiring
December 20, 2006
Question

input text field validation - design advice request

  • December 20, 2006
  • 3 replies
  • 560 views
Newbie here, so please be gentle.

I want to have some automatic validation of 2 input fields. One will allow integers only and another will allow decimals. I will also want to check that the numbers entered fall within a particular range. So a couple questions. First, I am trying to use OO techniques by developing classes. Should I write 2 new Classes called IntegerTextField and DecimalTextField that each subclass TextField? (If so, how should I intercept the key strokes inside these new classes so that I can check what has been entered.) Or is it better to create a new class that just holds static functions for checking fields and then call those functions as needed?

Second, does anyone have advice and/or a code snippet that demonstrates the best way to strip out non-numeric characters?

Thanks in advance for any help you gurus can provide.
This topic has been closed for replies.

3 replies

SPGAnneAuthor
Inspiring
December 21, 2006
Thank you very much LuigiL for lots of help not to mention code to make my work go faster. I so much appreciate your continued patience with me.
SPGAnneAuthor
Inspiring
December 21, 2006
I tried the Numerals thing again (I had tried that before as well) and the fields still let me type alpha characters in the field. What I would expect/want is that if a user types any non numeric character into the field, after the field loses focus those non numeric characters would be stripped out and the field display be updated to show only numeric characters or blank if they hadn't typed in any numerics.
Inspiring
December 21, 2006
Then use the 'restrict' property of the text field (hit F1 -> search TextField -> see Property Summery).
Inspiring
December 21, 2006
And if you still want to strip out the non-numerals you can check if the character falls within the ASCII range of numbers 0-9. See attached code.

Inspiring
December 20, 2006
Is there a reason why you can't just set the text field to only embed numeric integers?
SPGAnneAuthor
Inspiring
December 20, 2006
Oh boy. Am I being incredibly dumb? I had tried this by clicking on the embed button in the properties panel for my input text field. I then typed in 0123456789 in the Include these characters field. Then I ran my .fla in test mode and typed in abc into my input field and I was not prevented from doing that. So I thought I didn't understand this whole embed thing or it didn't do what I thought it would do. Did I do something wrong? Sorry to be so novice about all this.

Inspiring
December 20, 2006
In the embed options choose 'Numerals'.

As you might suspect, no need for subclasses. You just need to validate the input. Attached an example how to check whether a number is within (or out of) range.