RE: [PHP] Regular Expression

From: Date: Tue, 01 Jul 2003 13:46:13 +0000
Subject: RE: [PHP] Regular Expression
Groups: php.general 
Request: Send a blank email to php-general+get-153548@lists.php.net to get a copy of this message
[snip] I am currently using this piece of code to validate wether or not an address has only letters, numbers, #, or - in it: if (!ereg("^[A-Za-z0-9 #-]{1,20}", $_POST["address1"])) { $error = 1; $msg .= "Address must only contain letters, numbers, #, or -.<br>"; } However, if I put any valid character as the first, and then any illegal characters (!@$%, etc) after that, it passes it as ok. Can someone tell me what I am doing wrong with the regex? [/snip] It's not so much that your regex is wrong, but there are other functions that you may want to use, such as is_numeric(), is_integer(), is_string() (there is a good example of checking for an alphabetic string on the php site) HTH

« previous php.general (#153548) next »