Professional Web Applications Themes

Pattern matching for xx-xx-xx string - PHP Development

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....

  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. #2

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

    [email]jeffnospam.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

  3. #3

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

    *** [email]jeffnospam.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

  4. #4

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

    On Mon, 19 Jan 2004 18:47:08 +0100, Alvaro G Vicario
    <alvaro_QUITAR_REMOVEtelecomputeronline.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

  5. #5

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

    [email]jeffnospam.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

  6. #6

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

    Janwillem Borleffs wrote:
    > [email]jeffnospam.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

  7. #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

  8. #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

Similar Threads

  1. pattern matching
    By Tad McClellan in forum PERL Beginners
    Replies: 30
    Last Post: June 23rd, 07:42 PM
  2. Pattern Matching Operators
    By Prasad Karpur in forum PERL Beginners
    Replies: 2
    Last Post: October 5th, 04:21 PM
  3. Pattern matching username
    By perl@swanmail.com in forum PERL Beginners
    Replies: 1
    Last Post: September 30th, 05:37 PM
  4. matching the pattern (strings)
    By MJS in forum PERL Beginners
    Replies: 0
    Last Post: September 28th, 07:04 PM
  5. [PHP] mysql Pattern Matching
    By Cpt John W. Holmes in forum PHP Development
    Replies: 1
    Last Post: September 5th, 06:42 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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