--- Christopher E <[EMAIL PROTECTED]> wrote:
> I am trying to get example of how to check for a pattern of a string.
> The string could be a numbers or letters or numbers and letters.
You are asking about Regular Expressions, a flexible tool for pattern matching
which is available
for PHP and many other programming languages. There is a good book called
MASTERING REGULAR
EXPRESSIONS from O'Reilly which is an oft-cited resource. There are many good
websites as well.
> For example I want to check for a pattern of 1 letter then 2 numbers
> like this A01
One way to achieve this is to use listings of characters which are acceptable
in square brackets:
[A-Za-z][0-9]{2}
This indicates that the first character is an upper or lower case letter. The
second character is
a numeric digit. The 2 in curly braces indicates that there must be two of the
second pattern.
If you want one or two numbers after the letter:
[A-Za-z][0-9]{1,2}
> Other example would be 9 numbers long and only numbers like this 123456789
[0-9]{9}
> Also checking for zipcode patterns like 92103-3649 or 92103 <-- These
> are the only two ways I want for USA if there is a set of patterns for
> other countries then I will take these also just incase type thing. I
> would be showing the user the types of patterns that would be allowed
> so I am fine with this for now at less.
[0-9]{5}(-[0-9]{4})?
I haven't tested this. The first five values should only be numeric digits.
Note that in the New
England area many states have zips where the first of five digits is a zero.
The content
surrounded in parens would be placed in a memory location. Parens can also
group a RegEx. I am
trying to use the latter rule. Here we are looking for a hyphen character
followed by four
digits. The last part is optional so the question mark allows 0 or 1 of the
match to the left
(stuff in parens).
> One more thing if you could please explian what was done in each put
> of the pattern check.
>
> Thank YOU for your help!
James
_____
James D. Keeline
http://www.Keeline.com http://www.Keeline.com/articles
http://Stratemeyer.org http://www.Keeline.com/TSCollection
http://www.ITeachPHP.com -- Free Computer Classes: Linux, PHP, etc.
Spring Semester January-June 2006. Two new class topics.
Community email addresses:
Post message: [email protected]
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php-list/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/