[PHP] Looking for an easier regex check...

2002-04-29 Thread Joshua E Minnie

Does anybody know of a good way to make sure that a string contains ONLY
certain characters.  I tried using
ereg([~`!@#$%^*(){}-+=|\\/.,'\:;\[\]], $string); but I get parse
errors.  Besides that I only want the characters A-Za-z0-9_ in $string.  Is
there is simpler way to ensure this rather than checking to see if any of
the characters I don't want are in there?


Thank you for your help in advance.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Looking for an easier regex check...

2002-04-29 Thread Joshua E Minnie

Does anybody know of a good way to make sure that a string contains ONLY
certain characters.  I tried using
ereg([~`!@#$%^*(){}-+=|\\/.,'\:;\[\]], $string); but I get parse
errors.  Besides that I only want the characters A-Za-z0-9_ in $string.  Is
there is simpler way to ensure this rather than checking to see if any of
the characters I don't want are in there?


Thank you for your help in advance.


--
Joshua E Minnie/CIO
[EMAIL PROTECTED]
Phone: 616.276.9690
Fax: 616.342.8750
Nextel: 616.862.2847

Don't work for recognition, but always do work worthy of recognition.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Looking for an easier regex check...

2002-04-29 Thread Miguel Cruz

On Mon, 29 Apr 2002, Joshua E Minnie wrote:
 Does anybody know of a good way to make sure that a string contains ONLY
 certain characters. I tried using
 ereg([~`!@#$%^*(){}-+=|\\/.,'\:;\[\]], $string); but I get parse
 errors.

I'm surprised you get a parse error. I'd expect you would get a runtime 
error like REG_ERANGE.

Anyway, you need to escape all the characters that have special meanings 
in regular expressions. Try something like:

ereg([~!@#\$%^\*(){}\-\+=|\\/\.,'\:;\[\]a-zA-Z0-9], $string);

 Besides that I only want the characters A-Za-z0-9_ in $string. Is there
 is simpler way to ensure this rather than checking to see if any of the
 characters I don't want are in there?

miguel


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Looking for an easier regex check...

2002-04-29 Thread Joshua E Minnie

Worked great only you forgot to escape the carat character.  Thanks for the
help.

Josh

Miguel Cruz [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 On Mon, 29 Apr 2002, Joshua E Minnie wrote:
  Does anybody know of a good way to make sure that a string contains ONLY
  certain characters. I tried using
  ereg([~`!@#$%^*(){}-+=|\\/.,'\:;\[\]], $string); but I get parse
  errors.

 I'm surprised you get a parse error. I'd expect you would get a runtime
 error like REG_ERANGE.

 Anyway, you need to escape all the characters that have special meanings
 in regular expressions. Try something like:

 ereg([~!@#\$%^\*(){}\-\+=|\\/\.,'\:;\[\]a-zA-Z0-9], $string);

  Besides that I only want the characters A-Za-z0-9_ in $string. Is there
  is simpler way to ensure this rather than checking to see if any of the
  characters I don't want are in there?

 miguel




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php