日付文字列の入力チェック

by propg
RegExpValidator
♥0 | Line 45 | Modified 2011-04-28 10:12:57 | MIT License
play

ActionScript3 source code

/**
 * Copyright propg ( http://wonderfl.net/user/propg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kfR1
 */

<?xml version="1.0" encoding="utf-8"?>
<!-- forked from ashitaka's Flex4テンプレ -->
<s:Application
    xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/mx";
        @namespace controls "nt.controls.*";
        @namespace controls1 "labo.controls.*";
        @namespace code "http://code.google.com/p/flexlib/";
        
        s|Application {
            backgroundColor: #FFCCFF;
        }

        global {
            font-family: "MS UI Gothic", Verdana, Arial, Helvetica, sans-serif;
            fontSize:14px;
        }
    </fx:Style>

    <fx:Script>
        <![CDATA[
        import flash.events.KeyboardEvent;
        import flash.events.MouseEvent;
        import mx.events.FocusRequestDirection;
        private function OnClickHandler(event:MouseEvent):void {
            var myPattern:RegExp = /^([MTSHmtsh][0-9][0-9]|[0-2][0-9][0-9][0-9])[0-1][0-9][0-3][0-9]$/;
            var result:Boolean = myPattern.test(dateInput.text);
            resultMessage.text = result ? "OK" : "NG";
        }

        
        
        ]]>
    </fx:Script>

    <fx:Declarations>
        <mx:RegExpValidator  source="{dateInput}" property="text">
            <mx:expression><![CDATA[^([MTSHmtsh][0-9][0-9]|[0-2][0-9][0-9][0-9])[0-1][0-9][0-3][0-9]$]]></mx:expression>  
        </mx:RegExpValidator>
    </fx:Declarations>
    
    <s:layout>
        <s:VerticalLayout paddingLeft="5" paddingTop="5" paddingBottom="5" paddingRight="5"/>
    </s:layout>
    <s:Label text="日付入力チェック {'\n'}(YYYYMMDDか、EYYMMDDのみ許可: Eには和暦コード[MTSH])"/>
    <s:TextInput id="dateInput" restrict="[MTSHmtsh0-9]"/>
    <s:Button label="dummy1" click="{OnClickHandler(event)}"/>

    <s:Label id="resultMessage"/>
</s:Application>