Regular Expression Help?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vagabond Software

    Regular Expression Help?

    I'm trying to validate a text box that complies with the following rules:

    1) text can be blank/empty
    2) non-blank text shall contain ONLY A-Z and/or 0-9
    3) non-blank text shall contain a maximum of 6 characters

    Here is what I have so far...

    (^A-Z0-9*$){0,6}

    Don't look at it too long because it is not working as desired and will only
    throw you off the trail. Any help is greatly appreciated.

    carl


  • Martin Honnen

    #2
    Re: Regular Expression Help?



    Vagabond Software wrote:
    [color=blue]
    > I'm trying to validate a text box that complies with the following rules:
    >
    > 1) text can be blank/empty
    > 2) non-blank text shall contain ONLY A-Z and/or 0-9
    > 3) non-blank text shall contain a maximum of 6 characters
    >
    > Here is what I have so far...
    >
    > (^A-Z0-9*$){0,6}[/color]

    @"^[A-Z0-9]{0,6}$"

    --

    Martin Honnen --- MVP XML

    Comment

    • Lance

      #3
      Re: Regular Expression Help?

      > > I'm trying to validate a text box that complies with the following
      rules:[color=blue][color=green]
      > >
      > > 1) text can be blank/empty
      > > 2) non-blank text shall contain ONLY A-Z and/or 0-9
      > > 3) non-blank text shall contain a maximum of 6 characters
      > >
      > > Here is what I have so far...
      > >
      > > (^A-Z0-9*$){0,6}[/color]
      >
      > @"^[A-Z0-9]{0,6}$"[/color]

      I think you may want a space in there, if by rule one, you allow spaces:
      (A-Z0-9 ){0,6}

      If you only allow 6 chars, you may want to first grab a substring of the
      first six chars and then apply this validation. I'm not sure by your rules
      whether you need the beginning and end of string anchors....


      Comment

      Working...