Jump to content
MakeWebGames

Mailbox


MNG

Recommended Posts

$_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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...