Re: Regular Expression help

From: Date: Thu, 04 Jan 2007 16:46:35 +0000
Subject: Re: Regular Expression help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-246537@lists.php.net to get a copy of this message
Those patterns aren't anchored to the ends of the string, so as long as the string contains one matching character, the succeeds. ^ anchors the pattern to the beginning, \z to the end, so you want: /^[A-Za-z]+\z/ Or test the opposite case to see if it fails: /[^A-Za-z]/ Arpad Chris Boget wrote:
<?php echo 'Is String: [' . ( is_string( 'a1b2c3' ) && preg_match( '/[A-Za-z]+/', 'a1b2c3' )) . ']<br>'; echo 'Is Numeric: [' . ( is_numeric( 'a1b2c3' ) && preg_match( '/[0-9]+/', 'a1b2c3' )) . ']<br>'; echo 'Is String: [' . ( is_string( 'abcdef' ) && preg_match( '/[A-Za-z]+/', 'abcdef' )) . ']<br>'; echo 'Is Numeric: [' . ( is_numeric( '123456' ) && preg_match( '/[0-9]+/', '123456' )) . ']<br>'; ?> Why is the first "Is String" check returning true/showing 1? preg_match should fail because 'a1b2c3' contains numbers and, as such, doesn't match the pattern... What am I doing wrong? thnx, Chris


« previous php.general (#246537) next »