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) Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
purencool Posted October 27, 2010 Author Share Posted October 27, 2010 ta Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.