Page 1 of 1

Preg_Match Limit

Posted: Fri Feb 09, 2007 11:52 pm
by tecktalkcm0391
I have this code:

Code: Select all

<?php
$text = "AB-12345";

if(preg_match("/^([A-Za-z]+)\-([0-9]+)$/", $text)){
	echo "yes";
}

?>
Is there a way to make it so that the number after the "-" has to be a digit between 1-5 digits? Only 5 digits?

Thanks!

Posted: Fri Feb 09, 2007 11:56 pm
by volka
http://www.perl.com/doc/manual/html/pod/perlre.html wrote:The following standard quantifiers are recognized:

* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times
[0-9]{1,5}

Posted: Sat Feb 10, 2007 12:12 am
by tecktalkcm0391
Thanks!