Identifying allowed characters using Regular Expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hungrymind@gmail.com

    Identifying allowed characters using Regular Expression

    Hi all,

    I am developing some control (textbox based), to validate inputs to
    that control I am using regular expression, where pattern is generated
    dynamically. I need to identify what all charcters are allowed with
    that particular pattern. Is this possible or any way to solve this. Or
    else, i want to identify if only one character is allowed then that
    character will apear & user need not to enter any value for that.
    Please suggest if its possible.

    regards,
    - hungrymind


  • MumboJumbo

    #2
    Re: Identifying allowed characters using Regular Expression

    Ooops just realized i miss-read your post ...

    Sorry can't help ...

    MumboJumbo wrote:
    [color=blue]
    > yes you can do this i believe ...
    >
    > foreach (Match mymatch in REGEX.matchs(in putstr) {
    >
    > if (inputstr.Lengt h = mymatch.Length) {
    > //is ok
    > } else {
    > //not ok
    > }
    >
    > }
    >
    > hungrymind@gmai l.com wrote:
    >[color=green]
    >> Hi all,
    >>
    >> I am developing some control (textbox based), to validate inputs to
    >> that control I am using regular expression, where pattern is generated
    >> dynamically. I need to identify what all charcters are allowed with
    >> that particular pattern. Is this possible or any way to solve this. Or
    >> else, i want to identify if only one character is allowed then that
    >> character will apear & user need not to enter any value for that.
    >> Please suggest if its possible.
    >>
    >> regards,
    >> - hungrymind
    >> http://www.hungrymind.co.in
    >>[/color][/color]

    Comment

    • MumboJumbo

      #3
      Re: Identifying allowed characters using Regular Expression

      yes you can do this i believe ...

      foreach (Match mymatch in REGEX.matchs(in putstr) {

      if (inputstr.Lengt h = mymatch.Length) {
      //is ok
      } else {
      //not ok
      }

      }

      hungrymind@gmai l.com wrote:
      [color=blue]
      > Hi all,
      >
      > I am developing some control (textbox based), to validate inputs to
      > that control I am using regular expression, where pattern is generated
      > dynamically. I need to identify what all charcters are allowed with
      > that particular pattern. Is this possible or any way to solve this. Or
      > else, i want to identify if only one character is allowed then that
      > character will apear & user need not to enter any value for that.
      > Please suggest if its possible.
      >
      > regards,
      > - hungrymind
      > http://www.hungrymind.co.in
      >[/color]

      Comment

      • James Curran

        #4
        Re: Identifying allowed characters using Regular Expression

        Well, it's possible, but if I'm reading it right, it would pretty much
        involve writing your own Regular Expression parser.

        Give us a clearier idea of what you want to do, and perhaps we can
        recommend a solution.

        --
        --
        Truth,
        James Curran
        [erstwhile VC++ MVP]
        Home: www.noveltheory.com Work: www.njtheater.com
        Blog: www.honestillusion.com Day Job: www.partsearch.com

        <hungrymind@gma il.com> wrote in message
        news:1114177188 .287581.128390@ f14g2000cwb.goo glegroups.com.. .[color=blue]
        > Hi all,
        >
        > I am developing some control (textbox based), to validate inputs to
        > that control I am using regular expression, where pattern is generated
        > dynamically. I need to identify what all charcters are allowed with
        > that particular pattern. Is this possible or any way to solve this. Or
        > else, i want to identify if only one character is allowed then that
        > character will apear & user need not to enter any value for that.
        > Please suggest if its possible.
        >
        > regards,
        > - hungrymind
        > http://www.hungrymind.co.in
        >[/color]


        Comment

        • hungrymind@gmail.com

          #5
          Re: Identifying allowed characters using Regular Expression

          Thanks James for help,

          Here is the idea. There is a property in my control called Expression.
          This will have values like
          [1]#2[0-4]#[-]#3[0-9]#[-]#4[0-9]

          Based on numbers coming after before [ is used to calculate no of text
          boxes to be displayed (1 is assumed if such no does not exists) . All
          text boxes can contain single character only.
          All values contained in [] in Expression property are extracted & used
          as regular expression for corresponding text boxes.
          Like [1] means only 1 is allow in first text box. 0-4 is allowed in
          next 2 text boxes and so on. What all I need is identify allowed
          characters for each text box when control loads in the form so that if
          a particular text box has only one charcter allowed, that will appear
          on load itself & text box becomes uneditable.

          This is the idea. The code i have written is not very much descriptive
          at this point, I think concept will do for now.

          Thanks & regards,
          - hungrymind


          Comment

          • hungrymind@gmail.com

            #6
            Re: Identifying allowed characters using Regular Expression

            Please remmeber, i have to identify before any string in input in
            textbox, which means I can not use match to evaluate what all text are
            allowed like MumboJumbo has suggested
            [color=blue]
            > foreach (Match mymatch in REGEX.matchs(in putstr) {[/color]
            [color=blue]
            > if (inputstr.Lengt h = mymatch.Length) {
            > //is ok
            > } else {
            > //not ok
            > }[/color]
            [color=blue]
            > }[/color]

            Comment

            • James Curran

              #7
              Re: Identifying allowed characters using Regular Expression

              OK, I'm going to assume you've already gotten the code to separate
              [1]#2[0-4]#[-]#3[0-9]#[-]#4[0-9]
              into [1] [0-4] [0-4] [-] [0-9] [0-9] [0-9] [-] [0-9] [0-9] [0-9]
              [0-9]

              Now, to determine if it can only be one character, first eliminate all
              where there is more than one character bewteen the brackets. Here, that
              leaves us with just [1] [-] [-]. Now, we just have to look at that one
              character. There are very few one character regular expression special
              characters that would be meaningful in this context. Basically, there's "."
              (accept any character). If it's anything beside ".", than that's your one
              character.

              The only think you have to worry about that, is the few characters that
              require two characters to represent in a RE: Characters like . $ ^ { [ ( | )
              * + ? \ which need to be escaped .
              --
              --
              Truth,
              James Curran
              [erstwhile VC++ MVP]

              Home: www.noveltheory.com Work: www.njtheater.com
              Blog: www.honestillusion.com Day Job: www.partsearch.com

              <hungrymind@gma il.com> wrote in message
              news:1114234961 .055559.71970@o 13g2000cwo.goog legroups.com...[color=blue]
              > Thanks James for help,
              >
              > Here is the idea. There is a property in my control called Expression.
              > This will have values like
              > [1]#2[0-4]#[-]#3[0-9]#[-]#4[0-9]
              >
              > Based on numbers coming after before [ is used to calculate no of text
              > boxes to be displayed (1 is assumed if such no does not exists) . All
              > text boxes can contain single character only.
              > All values contained in [] in Expression property are extracted & used
              > as regular expression for corresponding text boxes.
              > Like [1] means only 1 is allow in first text box. 0-4 is allowed in
              > next 2 text boxes and so on. What all I need is identify allowed
              > characters for each text box when control loads in the form so that if
              > a particular text box has only one charcter allowed, that will appear
              > on load itself & text box becomes uneditable.
              >
              > This is the idea. The code i have written is not very much descriptive
              > at this point, I think concept will do for now.
              >
              > Thanks & regards,
              > - hungrymind
              > http://www.hungrymind.co.in
              >[/color]


              Comment

              • hungrymind

                #8
                Re: Identifying allowed characters using Regular Expression

                Thanks James, You got exactly what I wanted. Playing with strings was
                in my mind, & seems working fine. But anyhow, I didnt like the
                approach. This kind of alternative, I was looking for some solution
                which will really describe what all charcters are allowed. This will
                help me in giving error message like " only 0,1,2,3,4 are allowed in
                this field" and also in future as well. Thanks anyway, help
                appreciated. :)

                - hungrymind


                Comment

                Working...