1
我想要在Adobe Flex中验证IP地址的最佳解决方案。我目前的解决方案是使用正则表达式验证程序并查找虚线的四数字,请参阅下面的代码。出于某种原因,这也将允许像“1.2.3.4.5”这样的地址。有没有人有更好的解决方案?在Adobe Flex中验证IP地址的最佳方法
<?xml version="1.0" encoding="utf-8"?>
<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" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:RegExpValidator source="{ipAddr}" property="text"
expression="\d+\.\d+\.\d+\.\d+"
invalid="Alert.show('The IP address is invalid');"/>
</fx:Declarations>
<s:TextInput id="ipAddr" x="10" y="10"/>
<s:Button label="OK" x="10" y="40"/>
</s:Application>
在http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address看看 – 2012-03-27 19:59:50