Welcome Guest, Not a member yet? Register   Sign In
RegEx patterns = Not my strong point. Can I pick your brain?
#1

[eluser]stormbytes[/eluser]
So I'm writing a form_validation callback function that needs to identify if a particular string contains any characters *except* upper/lower case alpha, numeric, spaces, dashes/underscores.

So if you're a RegEx ninja..

Would you give me the pattern for a preg_match() ?

Thanks in advance
#2

[eluser]hybriid[/eluser]
/[^a-z0-9 _-]/ig
#3

[eluser]stormbytes[/eluser]
preg_match() [function.preg-match]: Unknown modifier 'g'
Code:
$pattern = "/[^a-z0-9 _-]/ig";

$string = "whatsG oi ng on";

echo preg_match($pattern, $string);
#4

[eluser]nuwanda[/eluser]
yeah, I got the unknown g thing a while back. Trying to recall how I solved it...
#5

[eluser]nuwanda[/eluser]
Ah, drop the g and use preg_match_all

And I use this all the time: RegXr
#6

[eluser]stormbytes[/eluser]
purrfect! Thanks
#7

[eluser]nuwanda[/eluser]
No worries.




Theme © iAndrew 2016 - Forum software by © MyBB