Can anyone help me with preg_match

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
N1gel
Forum Commoner
Posts: 95
Joined: Sun Apr 30, 2006 12:01 pm

Can anyone help me with preg_match

Post by N1gel »

I'm using preg_match to validate the data i get from a html form, i use it before i use the data in a query to insert it into my database.

the regular expression i am using is "^[ \w]{2,255}+$/"

As i understand it this only allows letters and numbers of a total length of between 2-255. This is fine for most of my form however one of my fields is a textarea and can contatin multiple lines. How can i adjust my regular expression to accept return carriages.

Any help would be greatfull. Thanks :D

Nigel
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What's the end goal in using this regex?
User avatar
N1gel
Forum Commoner
Posts: 95
Joined: Sun Apr 30, 2006 12:01 pm

Post by N1gel »

The idea of using the regular expresion is validating the form fields.

I am attempting to limit the form fields to just numbers and letters this is an attempted at preventing sql insertion on my site.

i do a comparisson with the form fields and the reg expression to make sure they are safe and just numbers and letters.

But in the text area people use multiple lines and ehen i do the comparisson the reg expression and fields don't match.

Hope i've made myself clear sorry i'm not good at explaing things
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why not use the escaping function(s) for your database wuch as mysql_real_escape_string(), pg_escape_string() and so forth?

What about punctuation? Shouldn't we be able to have punctuation in our text? What about accent characters. Some words we use can have accent characters in them.
Post Reply