Jump to content

regex


purencool

Recommended Posts

I have been playing with reg ex patterns for the last couple of hours. I realized I have been coding in security a hole. But for the life of me I don't know the answer.

 

In preg match it will return a 1 true. So the code below is saying if you find anything that is not one of these values the condition is true. Meaning anything but a-zA-Z true is this correct?

 

How do I make it so if you find anything but a-zA-Z return false?

if ( preg_match('/[a-zA-Z]/', $_GET['contact'] )== 1)

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/217034-regex/
Share on other sites

Hi, you do that by using the not operator before you character specifications ^:

 

if ( preg_match('/[^a-zA-Z]/', $_GET['contact'] )== 1)

 

also, you can use i to indicate case insensitivty so you don't need to put a-zA-Z (though I do):

 

if ( preg_match('/[^a-z]/i', $_GET['contact'] )== 1)

 

Note, the 'i' comes after your delimiter.

 

Hope that helps!

Link to comment
https://forums.phpfreaks.com/topic/217034-regex/#findComment-1127227
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.