3 Replies Latest reply on Dec 21, 2009 4:32 AM by Francisc

    Trouble Getting RegExpValidator to Properly Validate Time

    !_emily

      I'm trying to use a RegExpValidator to validate the text entered into a ComboBox. The ComboBox represents a time and its menu contains values on the half hour (i.e. 12:00 AM, 12:30 AM, 1:00 AM, etc.).

       

      With the RegExpValidator, validation always fails. However, when I test the input using the RegExp test() method, it validates properly.

       

      Here is my code:

       

      private const _timeRegEx:RegExp = /(0?[1-9]|1[0-2]):[0-5][0-9]\s+([ap]m|[AP]M)/;

       

      <mx:RegExpValidator id="regExpV"
          expression="{_timeRegEx}"  
           source="{timePicker}" property="text" triggerEvent="focusOut"
          valid="handleValidTime(event)" invalid="handleInvalidTime(event)"
          required="false"/>

       

      <mx:ComboBox id="timePicker"
          dataProvider="{_times}"
          editable="true" 
          width="100"/>

       

      Thanks for any help!