Hi Christopher,

<?php
$test1 = "X93";
if (preg_match("/^[a-zA-Z]{1}[0-9]{2}$/", $test1)) echo "Match found $test1";
else echo "No Match Found";

echo "<br /><br />";

$test2 = "84264-7364";
if (preg_match("/[0-9]{5}-[0-9]{4}/", $test2)) echo "Match found $test2";
else echo "No Match Found";

echo "<br /><br />";

$test3 = 12345;
if (preg_match("/^[0-9]{5}$/", $test3)) echo "Match found $test3";
else echo "No Match Found";
?>

It'd take to long to explain every step
Only thing that's not too obvious is ^ and $
^ is the pattern start and $ is the end
If you take them out, it'll match longer strings or numbers
Put different numbers in to fully test it.

Bob E.


----- Original Message ----- 
From: "Christopher E" <[EMAIL PROTECTED]>

> 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.
> 
> For example I want to check for a pattern of 1 letter then 2 numbers
> like this A01
> 
> Other example would be 9 numbers long and only numbers like this 123456789
> 
> 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.
> 
> One more thing if you could please explian what was done in each put
> of the pattern check.



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/
 



Reply via email to