Pattern matching for xx-xx-xx string

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Pattern matching for xx-xx-xx string

    Hello,

    What is the syntax to make sure the user has entered this pattern in a
    web form:

    xx-xx-xx

    where x are integers, for example: 12-53-89

    Can anybody help?

    Thanks.
    jeff@nospam.com Guest

  2. Similar Questions and Discussions

    1. pattern matching
      brian liu <xliu75@yahoo.com> wrote: or $defaultDir='d:/haha'; or
    2. Pattern Matching Operators
      Is there a similar operator in Perl for ${variable##pattern} as there is in korn shell. Thanks for the help. Prasad ...
    3. Pattern matching username
      Is this doing what it is suppose to and how efficient? rule - valid chars A-z0-9 _ - . - cannot start with a digit - cannot start with a space...
    4. [PHP] mysql Pattern Matching
      From: "Ralph Guzman" <ralph213@sbcglobal.net> Actually no, I guess there isn't. Neither one will use an index. mysql> desc test;...
    5. mysql Pattern Matching
      i'm doin this offlist -----Original Message----- From: Ralph Guzman Sent: Thursday, September 04, 2003 10:23 PM To: PHP General Mailing List...
  3. #2

    Default Re: Pattern matching for xx-xx-xx string

    [email]jeff@nospam.com[/email] wrote:
    > Hello,
    >
    > What is the syntax to make sure the user has entered this pattern in a
    > web form:
    >
    > xx-xx-xx
    >
    > where x are integers, for example: 12-53-89
    >
    With preg_* functions, use:
    "/^(\d{2}-){2}\d{2}$/"

    With ereg* functions, use:
    "^([0-9]{2}-){2}[0-9]{2}$"


    JW



    Janwillem Borleffs Guest

  4. #3

    Default Re: Pattern matching for xx-xx-xx string

    *** [email]jeff@nospam.com[/email] wrote/escribió (Mon, 19 Jan 2004 17:26:14 +0000):
    > What is the syntax to make sure the user has entered this pattern in a
    > web form:
    >
    > xx-xx-xx
    >
    > where x are integers, for example: 12-53-89
    [0-9][0-9]-[0-9][0-9]-[0-9][0-9]
    [0-9]{2}-[0-9]{2}-[0-9]{2}

    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --
    Alvaro G Vicario Guest

  5. #4

    Default Re: Pattern matching for xx-xx-xx string

    On Mon, 19 Jan 2004 18:47:08 +0100, Alvaro G Vicario
    <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote:
    >[0-9][0-9]-[0-9][0-9]-[0-9][0-9]
    >[0-9]{2}-[0-9]{2}-[0-9]{2}
    Thanks, it works if format is correct:

    if ( ereg ("[0-9]{2}-[0-9]{2}-[0-9]{2}", $INPUT_bank_sort_code) )
    {
    print "Yep, OK";
    }


    However, I want the function to work if it's wrong. What is the
    syntax? I thought it would be:

    if ( ereg ("^([0-9]{2}-[0-9]{2}-[0-9]{2})", $INPUT_bank_sort_code) )
    {
    print "Nope, the format is wrong";
    }

    but it does not work. What is the correct syntax?

    Thanks
    jeff@nospam.com Guest

  6. #5

    Default Re: Pattern matching for xx-xx-xx string

    [email]jeff@nospam.com[/email] wrote:
    > However, I want the function to work if it's wrong. What is the
    > syntax? I thought it would be:
    It's time for you to look into the manual:

    if ( !ereg(.....


    JW



    Janwillem Borleffs Guest

  7. #6

    Default Re: Pattern matching for xx-xx-xx string

    Janwillem Borleffs wrote:
    > [email]jeff@nospam.com[/email] wrote:
    >> However, I want the function to work if it's wrong. What is the
    >> syntax? I thought it would be:
    >
    > It's time for you to look into the manual:
    >
    > if ( !ereg(.....
    >
    >
    > JW
    *Grin* saying that,

    if (!strcasecmp(.. wouldn't do what you would think and does confuse newbies
    to PHP and C/C++ for that matter ;)

    ~Cameron
    Cameron Guest

  8. #7

    Default Re: Pattern matching for xx-xx-xx string

    Cameron wrote:
    > if (!strcasecmp(.. wouldn't do what you would think and does confuse
    > newbies to PHP and C/C++ for that matter ;)
    >
    Nothing that can't be fixed by reading the manual ;-)


    JW



    Janwillem Borleffs Guest

  9. #8

    Default Re: Pattern matching for xx-xx-xx string

    Janwillem Borleffs wrote:
    > Cameron wrote:
    >> if (!strcasecmp(.. wouldn't do what you would think and does confuse
    >> newbies to PHP and C/C++ for that matter ;)
    >>
    >
    > Nothing that can't be fixed by reading the manual ;-)
    >
    >
    > JW
    manual?! PSH! I'm a MAN! I fiddle till I get it right!

    lol nah, I jest, the PHP website manual is REALLY useful, and well designed
    may I add.

    ~Cameron
    Cameron Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139