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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegExp question 1

Status
Not open for further replies.

pixelz

Programmer
May 8, 2006
32
GB
Hi there,

I'm trying to validate a string input using the RegExp object. One of the things I want to watch out for is the entry but I'm having problems putt...as on how I can get around this? Cheers Pix
 
Ah nice! didn't know you could define the flag outside the deinition like that. hmmmm... very tasty...

Seems to work fine on the [url, but I've got another small issue. Another thing I'm testing on is <script and, following the above eg, I've tried:

Code:
var thisReg = /<script/i;

but this doesn't seem to pick it up. Neither does

Code:
var thisReg = /\<script/i;

or any variation... I con't seem to find a reference to the '<' character being reserved in any way, but it just doesn't seem to be picking it up.

any ideas?

cheers

Pix
 
I have firefox here and IE 6 but it works ok here, no need to escape the < character. Maybe you need more instances of <script to be replaced, to do that make the regexp global (g)

alert('<script\n<script\n'.replace(/<script/i,"hallo"));
alert('<script\n<script\n'.replace(/<script/ig,"hallo"));


Greetings, Harm Meijer
 
Ah brilliant! thanks for that.

Actually, I just noticed that it is picking it up. Sorry about that - I've got a script matching up the entry to a list of possible SQL injection attacks and one that sanitises the content of the entry - they both work in conjunction and, well, were working a little too well! :D

Thanks for the help!

cheers!

pix
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top