hi

i have a form. user enters value into it.

the value should be as follows

  • is *-

and the *s can equal anything, as long as they are equal. if they arent equal, the form wont continue. and the spaces and the dash after must be there also, or the form shouldnt execute.

i have tried accomplishing the with eregi, but ive had no luck so far.

thanks!

    First, you should use the preg functions instead of the ereg functions (which are essentially deprecated).

    Anyway, could you give a couple specific examples of strings that should match, and maybe one or two that should not match but almost do? This is just to give me a better idea of what your actual requirements are. For instance, can the values for the "*" locations be any number of characters? Is "is" always "is", or can it be any string, and if any string can it have spaces in it?

      NogDog;10895802 wrote:

      First, you should use the preg functions instead of the ereg functions (which are essentially deprecated).

      Anyway, could you give a couple specific examples of strings that should match, and maybe one or two that should not match but almost do? This is just to give me a better idea of what your actual requirements are. For instance, can the values for the "*" locations be any number of characters? Is "is" always "is", or can it be any string, and if any string can it have spaces in it?

      i was thinking about preg.

      anyways, here are some strings

      1 is 1-
      a is a-
      g4 is g4-
      lol is lol-
      no is no-
      0000 is 0000-
      543210 is 54321-
      a7a72 is a7a72-

      and some strings that should not work

      a is b-
      4 is 1-
      abc is 12-
      life is death-
      test is tset-
      4f3g is 4f3g-

      and special characters could work, as long as it cant become a security breach. originally i was planning on [a-zA-Z0-9] or something along those lines, but special characters are fine, granted they dont allow mysql injection or xss, etc.

      so if you can incorporate special characters, here would be some examples

      a$ is a$-
      @3# is @3#-
      l@l is l@l-

      and that dont work

      $#@ is T$#-
      $g4^ is #W@#sd-
      %HE is 3SgE3@-

      you should get the idea

      thanks so much!

        untested:

        if(preg_match('/^(\S*) is \1-$/', $string))
        {
           // it matches
        }
        
          NogDog;10895823 wrote:

          untested:

          if(preg_match('/^(\S*) is \1-$/', $string))
          {
             // it matches
          }
          

          you rule!! thanks so much!

          but how do i change it the strings to look for an extra dash? such as

          a is a--
          b is b--
          123 is 123--

          etc

          thanks in advace

            Use a + to mean "one or more", e.g., '-+'.

              6 days later
              laserlight;10895840 wrote:

              Use a + to mean "one or more", e.g., '-+'.

              im still a bit confused. can you demonstrate where and how that would be incorporated into the current code?

              thanks

                It would be something like this:

                if(preg_match('/^(\S*) is \1-+$/', $string))
                {
                   // it matches
                }
                  laserlight;10896699 wrote:

                  It would be something like this:

                  if(preg_match('/^(\S*) is \1-+$/', $string))
                  {
                     // it matches
                  }

                  Genious!

                  i was thinking to put the -+ after the..well, without touching the...
                  its hard to explain - stupid mistake.
                  thanks anyway!

                    Write a Reply...