Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex and line breaks in text area

Status
Not open for further replies.

webdev007

Programmer
Sep 9, 2005
168
The input from a text area form is:
$experience=nl2br($_POST['experience']);

Then I have a class with a few functions that check for a lot of possible hacks from injection to bad words etc..
My problem is that with or without nl2br() my regex is always rejecting the form input.

BUT if I use only one line and indeed do not type "enter" then all goes well

I think the way I wrote my regex is wrong (I am deficient with reg expressions)
I try to allow for 0 or any recurring occurrences of the result of nl2br which is <br />by using the following function:
function PregLongText($any_text)
{
if (!preg_match("/^[a-zA-Z0-9 ]*[\<br \/\>]+$/",$this->any_text=$any_text) )
{
return(1);

else
{
return(0);
}

How could I make it working?
Thanks
 
>if (!preg_match("/^[a-zA-Z0-9 ]*[\<br \/\>]+$/",$this->any_text=$any_text) )
[tt]if (!preg_match("/^[a-zA-Z0-9 ]*[red]([/red]\<br \/\>[red])[/red]+$/[red]m[/red]",$this->any_text=$any_text) )[/tt]
 
Thanks Tsuji,
I am sorry to report that it does not work
and not even with a single line
the way the function is used or call is not a problem I have no error and with another pattern for another segment it does the job fine.

Could it be as I suppose the textarea input
but on another hand using nl2br() suppresses mac, windoes and unix return line or break
so the only tag generated when pressing enter in text area has to be <br />
 
I also needed to allow for a few chars so I did the following which works due to /m

if (!preg_match("/^[a-zA-Z0-9 \,\.\-\$\:\!\?\/\< \>]+$/m",$this->any_text=$any_text) )
 
Problem probably is coming from \r. Try this instead.
[tt] if (!preg_match("/^[a-zA-Z0-9 ]*<br \/>\r?$/m",$this->any_text=$any_text) )[/tt]
(I have not taken into account whatever you want to convey in your last post. I do not understand it without reading it many more times.)
 
Tsuji, thanks again
your method:

if (!preg_match("/^[a-zA-Z0-9 ]*<br \/>\r?$/m",$this->any_text=$any_text) ) works fine but as is it does not allow for those chars: \,\.\-\$\:\!\?

if I use my old pattern laong with:+$/m",
then it all works fine, so now this is what I have
if (!preg_match("/^[a-zA-Z0-9 \,\.\-\$\:\!\?\/\< \>]+$/m",$this->any_text=$any_text) )

the reason behind it is
above I use an eregi() to disallow any type of brakets and such terms as "drop" "unlink" and more in the same range

on another hand since this concerns any plain text I also need to allow the user submitted text to possibly contains any of: \,\.\-\$\:\!\?
I understand that your solution looks more elegant
since mine now is fixed please do feel that you need spending more time.
I just wanted to explain the reasons why I did include those other characters.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top