1 Reply Latest reply on Sep 1, 2009 12:06 PM by ShardulSingh

    Use RegEx to check for whitespace

    lee704 Level 1

      I have the following RegEx that checks for 1) string between 12 and 35 characters in length, 2) string contains at least one digit, 3) string contains at least one lowercase alpha character, 4) string contains at least one uppercase alpha character, 5) string contains one special character.

       

      ^.*(?=.{12,35})(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[.!@#$%^&*+=]).*$

       

      The only thing else I need to add is a check for any whitespace characters anywhere in the string.  I tried the following but it allowed whitespace in the string:

       

      ^.*(?=.{12,35})(?!.*[\\s])(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[.!@#$%^&*+=]).*$

       

      Could someone advise where I am going wrong with this?

       

      Thanks!

        • 1. Re: Use RegEx to check for whitespace
          ShardulSingh Level 3

          Hi,

          I don’t have your complete code.But I am giving you as a demo code,

          In this I have not allowed the white space so white space is not being

          Allowed on the textbox.Hope this will help you.Please let me know if you have any issue with this.

           

           

           

           

          <?xml version="1.0" encoding="utf-8"?>

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

          <mx:Script>

                <![CDATA[

                [Bindable]

                private var regExpForFile : String

                = "0-9A-Za-z\\&\\`\\~\\!\\@\\#\\$\\%\\^\\(\\)\\-\\_\\=\\+\\]\\}\[\\'\\;\\,\\.\\{";

                ]]>

          </mx:Script>

                <mx:VBox horizontalAlign="center" width="350">

                      <mx:Label text="Enter File Name"/>

                      <mx:TextInput id="fileName" width="170" height="20"  restrict="{regExpForFile}"/>

                </mx:VBox>

          </mx:Application>

           

           

           

           

           

           

           

           

           

          With Regards,

           

          Shardul Singh Bartwal