[PHP] Regular Expression

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

  1. #1

    Default RE: [PHP] Regular Expression

    Thanks Wendell. This is exactly what I was looking for.

    -----Original Message-----
    From: Wendell Brown [mailto:wbrown@arkie.net]
    Sent: Tuesday, July 08, 2003 4:47 AM
    To: PHP General Mailing List
    Subject: Re: [PHP] Regular Expression

    On Mon, 07 Jul 2003 21:59:23 -0700, Ralph Guzman wrote:
    >I have a form where I have to check whether user is submitting a PO Box
    >as an address. I wrote the following using eregi, but it returns true
    >even when the field is not Po Box. How do I go about doing this
    >properly?
    >
    >if(eregi("^Po Box$", $address)){
    > $error_message_custom = "You cannot use a PO BOX for Bill To
    Address";
    >}
    I think this would do better...

    if( preg_match( "/P[\. ]*O\.* +BOX/i", $address ) )

    This will look for a "P" followed by a space, period or an "O" followed
    by a period and/or one or more spaces and the word BOX. It will also
    ignore case.


    --
    PHP General Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php



    Ralph Guzman Guest

  2. Similar Questions and Discussions

    1. Regular Expression
      Hi, I am writing a script that parses an html file (which has been retrieved as a scalar by LWP::UserAgent). The script looks for everything in...
    2. Regular expression help
      Hi, I'm pretty new to regular expressions. Before, I used to write long-winded and buggy segments of code with PHPs string functions to extract...
    3. Regular expression for both first and last name?
      I'm new to regular expressions, can someone explain to me how I can write one that will check for 2 names, at least, for a name field? Thanks!...
    4. help on regular expression
      Hi, I need some help on regular expression... i have following in variable $total_count $total_count = "##I USBP 000001 10:38:09(000)...
    5. [PHP] REGULAR EXPRESSION HELP
      John wrote: Your "newline" may be \r\n or \r instead of just \n. -- ---John Holmes... Amazon Wishlist:...
  3. #2

    Default Re: [PHP] Regular Expression

    On Tue, Jul 08, 2003 at 06:47:26AM -0500, Wendell Brown wrote:
    >
    > I think this would do better...
    >
    > if( preg_match( "/P[\. ]*O\.* +BOX/i", $address ) )
    Unless preg_match does something non-standard, you don't need to escape
    a period that's inside square brackets. In fact, the regexp you've
    built will also match an $address of "p\o box".

    --
    Paul Chvostek <paul@it.ca>
    it.canada [url]http://www.it.ca/[/url]
    Free PHP web hosting! [url]http://www.it.ca/web/[/url]

    Paul Chvostek 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