Well - just spent some time with this.  Here's what I came up with.  
Sloppy, but it works.  This allows standard times (1:00, 12:00, 
12:59), but not military time (24:00, 13:59, etc.).

private function validateTime():void {
        var setTime:String = new String;
        setTime = timeToAdd.text;
        if ((setTime.length == 4 && setTime.charAt(1) == ":" && int
(setTime.charAt(0)) >= 1 && int(setTime.charAt(0)) <= 9 && int
(setTime.charAt(2)) <= 5 && int(setTime.charAt(3)) <= 9)
         || (setTime.length == 5 && setTime.charAt(2) == ":" && int
(setTime.charAt(0)) == 1 && int(setTime.charAt(1)) <= 2 && int
(setTime.charAt(3)) <= 5 && int(setTime.charAt(4)) <= 9)) {
                Alert.show("Valid Number");
        } else {
                Alert.show ("Plesae enter a correct time (i.e. 12:00, 
9:00, etc.");
        }
}
<mx:HBox>
        <mx:Label text="Type in a Time:"/>
        <mx:TextInput id="timeToAdd" width="100%" text="12:00" />
</mx:HBox>

--- In [email protected], "qnotemedia" <[EMAIL PROTECTED]> 
wrote:
>
> Having the same problem here.  IMHO, this is so much easier in CF7 
> Flash Forms with the mask property (mask="99:99" always forces four 
> numbers with a colon in the middle), and I'm not sure why it has to 
> be as complicated as it is in Flex2.
> 
> The closest I've gotten is by using a number validator and changing 
> the decimalSeparator property to colon.  Unfortunately, this will 
> still allow "times" like 1:234, 123:4, 1234, etc.  I'm assuming 
> though you can probably develop something with RegExp, but I don't 
> quite understand enough about regular expressions.
> 
> Another interesting thing...I noticed that DateChooser's 
selectedDate 
> property includes time as part of its data.  Any way to format or 
> access that?
> 
> Agreed though - surely someone has taken care of this.
> 
>  - Chris
> 
> --- In [email protected], "boy_trike" <boy_trike@> wrote:
> >
> > Flex has a NUMBERformatter and a DATEFormatter.  I have the need 
> for a time formatter and 
> > would not like to re-invent what someone else must have already 
> done.  Ideally I want to 
> > have a textinput field which restricts input to 0-9: APM.  I 
would 
> like to accept the following 
> > and convert all to 3PM
> > 
> > 3P
> > 3
> > 3:00
> > 03:00
> > 15:00
> > 3:00PM
> > 
> > Of course, if the time is invalid (i.e. 2:65PM, 25:2, etc.) I 
would 
> like to display an error
> > 
> > Does something like this exist or must I roll my own?
> > 
> > thanks:
> > 
> > Bruce
> >
>







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/flexcoders/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to