Jump to content

Recommended Posts

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&#039;" 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 '&#039;'. 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

Link to comment
https://forums.phpfreaks.com/topic/241922-preg_match/
Share on other sites

 

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/241922-preg_match/#findComment-1242405
Share on other sites

 

i've closed off the other post so i'm just relying on this one now

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/241922-preg_match/#findComment-1242412
Share on other sites

 

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.

Link to comment
https://forums.phpfreaks.com/topic/241922-preg_match/#findComment-1242416
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.