knobby2k Posted July 13, 2011 Share Posted July 13, 2011 Hi guys, got a bit of a problem! well not so much a problem but i'm a bit confused of what to do for the best. basically i am trying to do a preg_match to validate names being entered into an input field using the following code: if ( !preg_match("/^([a-z\-\' ])+$/i", $this->input[$field]) ) The only characters that i want to allow through are... a-z - ' however, it still will not allow me to enter a ' into the field and i think i know why... when i go to view source on the page it displays this: <p>*First Name: <input type="text" name="firstname" value="John'" maxlength="80" /> It's cleansing the data earlier on in the script here: $data[$key] = trim(htmlspecialchars(strip_tags(stripslashes($value)), ENT_QUOTES, 'UTF-8')); so converting the apostrophe to '''. Obviously with me then doing a preg_match it is refusing the '&#;'. Now my question is... A) do i allow for '&#;' in the preg_match OR B) remove the htmlspecialchars any suggestions? cheers Quote Link to comment https://forums.phpfreaks.com/topic/241922-preg_match/ Share on other sites More sharing options...
wildteen88 Posted July 13, 2011 Share Posted July 13, 2011 I'd just apply htmlentities once the username has been validated/verified. Quote Link to comment https://forums.phpfreaks.com/topic/241922-preg_match/#findComment-1242397 Share on other sites More sharing options...
knobby2k Posted July 13, 2011 Author Share Posted July 13, 2011 I'd just apply htmlentities once the username has been validated/verified. so pass through preg_match to validate that the data is what i expect/require then run that variable through htmlentities? thanks Quote Link to comment https://forums.phpfreaks.com/topic/241922-preg_match/#findComment-1242399 Share on other sites More sharing options...
Maq Posted July 13, 2011 Share Posted July 13, 2011 @knobby, don't double post: http://www.phpfreaks.com/forums/index.php?topic=338621.0;topicseen & the second part of your question: http://www.phpfreaks.com/forums/index.php?topic=338621.msg1595762#msg1595762 Quote Link to comment https://forums.phpfreaks.com/topic/241922-preg_match/#findComment-1242402 Share on other sites More sharing options...
knobby2k Posted July 13, 2011 Author Share Posted July 13, 2011 @knobby, don't double post: http://www.phpfreaks.com/forums/index.php?topic=338621.0;topicseen & the second part of your question: http://www.phpfreaks.com/forums/index.php?topic=338621.msg1595762#msg1595762 wasn't sure where best to have the question... the original question was why it wouldn't accept the apostrophe... once i figured that out I wanted to know which was the best way to cleanse the data and thought the question wasn't suitable for the other board. Quote Link to comment https://forums.phpfreaks.com/topic/241922-preg_match/#findComment-1242405 Share on other sites More sharing options...
knobby2k Posted July 13, 2011 Author Share Posted July 13, 2011 @knobby, don't double post: http://www.phpfreaks.com/forums/index.php?topic=338621.0;topicseen & the second part of your question: http://www.phpfreaks.com/forums/index.php?topic=338621.msg1595762#msg1595762 i've closed off the other post so i'm just relying on this one now thanks Quote Link to comment https://forums.phpfreaks.com/topic/241922-preg_match/#findComment-1242412 Share on other sites More sharing options...
Maq Posted July 13, 2011 Share Posted July 13, 2011 @knobby, don't double post: http://www.phpfreaks.com/forums/index.php?topic=338621.0;topicseen & the second part of your question: http://www.phpfreaks.com/forums/index.php?topic=338621.msg1595762#msg1595762 i've closed off the other post so i'm just relying on this one now thanks In the future, post where you think it most belongs, if your question mutates or just simply doesn't belong there, it can be moved. Double posting will ultimately waste peoples' time. Quote Link to comment https://forums.phpfreaks.com/topic/241922-preg_match/#findComment-1242416 Share on other sites More sharing options...
AyKay47 Posted July 13, 2011 Share Posted July 13, 2011 knobby, I provided answers on your other thread.... Quote Link to comment https://forums.phpfreaks.com/topic/241922-preg_match/#findComment-1242430 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.