Validate hostname with RegExpValidator in Flex

I spent quite some time trying to get this working. The documentation available for RegExpValidator is not very extensive just to put it in a nice way.

All I needed to do is validate a string to verify if it follows the pattern of a hostname.

After much work and research I finally narrowed it down and here it is:

<mx:RegExpValidator id="regExpV"
source="{tbDomainName}" property="text"
flags="i" expression="^[a-zA-Z0-9\-\.]+\.[A-Za-z]\{2,6\}$"
/>

Notice the backslashes for escaping { and }  as these characters are used in Flex for data binding.

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)