Forum Moderators: coopster & phranque

Message Too Old, No Replies

regex with multiple fields delimiter

fields split with <br>

         

idiotgirl

4:04 pm on Jan 12, 2002 (gmt 0)

10+ Year Member Top Contributors Of The Month



ugh. A form allows for multiple selections to be stored to the database under one field name using
<BR>
to split the multiple entries.

EX:

field:data¦color:pink<BR>blue<BR>red<BR>¦field:data

Problem is - I need to regulate everything going into that field - only numerals, alphas, and white space is okay.

Every time I try to regex the field input, and convert to lower case, I have to take into consideration the

<BR>
splitting the fields when the data is actually written to the database, or retrieved for later editing.

Nothing works. Granted, I'm bad at regexing, but my patience with errors is running thin, also.

Need help.

gethan

5:53 pm on Jan 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I simplified the problem to:

match this "red<br>green<BR>etc<br>" or "red" or even " "

but

do not match this "red<br>green<nastytag><br>" or "¦some hack$> code"

Heres the pattern I used [perl]/^(<br>¦[\w\s]*)*$/i[/perl]

Don't copy and paste this as the ¦ symbol gets converted somewhere... typing it will work though.

Gethan

idiotgirl

6:20 pm on Jan 12, 2002 (gmt 0)

10+ Year Member Top Contributors Of The Month



gethan - I thought a solution had presented itself - while I was looking for help I just did:

if ($in{'color'} =~ /[^\w-\s\<BR>]/) { 
print "Knock that off and quit entering a bunch of crap";
}

And it seemed to be working okay. I forgot I allowed hypens, too. duh.

Now I check back and looks like that was pretty much right. Every now and then I surprise myself.

<added>but you had the order right! NOW I see </added>

gethan

6:33 pm on Jan 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



idiotgirl, your regexp don't look quite right .. does it still let valid stuff through?

Love the error message though ;)

idiotgirl

6:58 pm on Jan 12, 2002 (gmt 0)

10+ Year Member Top Contributors Of The Month



Well- I just dinked some with it (mine) and it screened out all my attempts to enter bogus data.

Yours worked, too, using

unless
instead of
if
.

I spent three days fixing hundreds or corrupted lines because the 'user' decided to write War & Peace in the freaking form fields and use every punctuation symbol known to man.

I wrote some rather hostile error messages. I am - without a doubt - the error message queen. (Both in creating scripting errors and writing the actual messages.)