Re: Ereg ()
| From: | DrouetL at ldnegoce dot com | Date: | Tue, 16 Apr 2002 13:51:37 +0000 |
| Subject: | Re: Ereg () | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-93187@lists.php.net to get a copy of this message | ||
Thanks for this answer.
But how can i test if i actually have numbers AND letters ?
Laurent Drouet
Erik Price
<pricee@hhbrow To: DrouetL@ldnegoce.com
n.com> cc: php-general@lists.php.net
Subject: Re: [PHP] Ereg ()
16/04/02 15:44
On Tuesday, April 16, 2002, at 08:49 AM, DrouetL@ldnegoce.com wrote:
>
> I'm new with RegEx and I would like to use them to validate my forms
> entries submitted to the server.
>
> My question is how can I verify with the regex that a string is
> - at least 7 chars
> - contains Chars and Nums
> - may contains some special chars (ex : % ! : ; , )but not in first or
> last
> position .
I'm assuming that by Chars you mean uppercase/lowercase letters?
Numbers are characters too, I thought.
preg_match('/^[A-Za-z0-9][A-Za-z0-9%!:;,]{5,}[A-Za-z0-9]$/', $string);
The above regex will only match a string that begins with A-Z or a-z or
0-9, then any number of characters that are in the middle character
class, then a final A-Z or a-z or 0-9.
I think. Try it out, that's untested.
Erik
----
Erik Price
Web Developer Temp
Media Lab, H.H. Brown
pricee@hhbrown.com