Jump to content

a regex question


Buyocat

Recommended Posts

I'm trying to do a really simple regular expression, but it doesn't seem to be working.  I want to check that  a string contains only numbers, letters and the "_.-" characters.  (Obviously they don't have to be in a string like that)  Anyway here is what I have created, the problem it is it never evaluates properly -- it just evaluates to false regardless of what I feed it.

[code]
$pattern = '[^a-zA-Z0-9_.-]{6,}'; // I want it to be at least 6 characters in length
$string = 'helloworld'; // pick any string you want
if (eregi($pattern, $string)) echo 'true';
else echo 'false'; // it is only echoing false
[/code]
Link to comment
https://forums.phpfreaks.com/topic/16113-a-regex-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.