purencool Posted October 27, 2010 Share Posted October 27, 2010 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 More sharing options...
Anti-Moronic Posted October 27, 2010 Share Posted October 27, 2010 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 More sharing options...
purencool Posted October 27, 2010 Author Share Posted October 27, 2010 ta Link to comment https://forums.phpfreaks.com/topic/217034-regex/#findComment-1127231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.