MNG Posted March 2, 2015 Share Posted March 2, 2015 $_POST['user1'] = (isset($_POST['user1']) && preg_match("/^[a-z0-9_]+([\\s]{1}[a-z0-9_]|[a-z0-9_])+$/i", $_POST['user1']) && ((strlen($_POST['user1']) < 32) && (strlen($_POST['user1']) >= 3))) ? $_POST['user1'] : ''; $_POST['user2'] = (isset($_POST['user2']) && preg_match("/^[a-z0-9_]+([\\s]{1}[a-z0-9_]|[a-z0-9_])+$/i", $_POST['user2']) && ((strlen($_POST['user2']) < 32) && (strlen($_POST['user2']) >= 3))) ? $_POST['user2'] : ''; Anyway I can change this to allow symbols but not allow apostrophes? Quote Link to comment Share on other sites More sharing options...
G7470 Posted March 2, 2015 Share Posted March 2, 2015 The preg_match should be: /^[a-z0-9_]+([\\s]{1}(([a-z0-9_\S]|[a-z0-9_\S])+[^\']))+$/i However, this may play a problem in code (as PHP recognizes ' as the start/end of a string), so this may not work...but that would be what it is. Source: http://www.regexr.com/ - good resource if you want to try building custom regular expressions like this in the future. ~G7470 Quote Link to comment Share on other sites More sharing options...
Sim Posted March 2, 2015 Share Posted March 2, 2015 I think this function would be best for checking for a single character. http://php.net/stristr Quote Link to comment Share on other sites More sharing options...
G7470 Posted March 2, 2015 Share Posted March 2, 2015 I think this function would be best for checking for a single character. http://php.net/stristr Could be, but you have to also account for the current expression match based upon what exactly you are looking for. Maybe you could do a combination of both, like use the expression match but then also say that this function (stristr) must return false as well in order for the condition to be satisfied. If you use stristr(), you could also put the apostrophe into a variable or something like that in order to ensure that it is taken as an apostrophe instead of a string beginning/end tag like what the PHP compiler will probably do with the expression match I gave you. ~G7470 Quote Link to comment Share on other sites More sharing options...
MNG Posted March 2, 2015 Author Share Posted March 2, 2015 Thanks guys. 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.