Regular Expressions and Arrays (Javascript)
by jkeilholz <jkeilholz(at)triad.rr.com>
|
| Date: |
Tue, 27 Nov 2001 04:27:16 -0800 (PST) |
| To: |
hwg-techniques(at)hwg.org |
| |
todo: View
Thread,
Original
|
|
Hello All!
I am having a bit of a dilemma with matching regular expressions against
arrays. What I am wanting to have happen is that a visitor will input a code
they are given and then be taken to an appropriate page. I've got the code
to work for exact entry BUT the client wants the code to make sure I have it
written to be case-insensitive. How can I go about checking arrays against
regular expressions? I've included my script here to help out.
Thanks in Advance,
Joe Keilholz
<script>
<!--
function discountDirect(){
var discount = /[agmps](.*?)0{3}2{1}/ig;
var dname = prompt("Please enter your discount code, if you do not have a
code simply enter \"success-20002\"","success-20002");
var dscntname = dname.match(discount);
if (dscntname != null){
var discountname = dscntname[0];
}
else{
var discountname = "x";
}
var discounts = new Array ();
discounts["AGC-0002"] = "a";
discounts["GTCC-0002"] = "b";
discounts["MEMB-0002"] = "c";
discounts["PAI-0002"] = "d";
discounts["SPX-0002"] = "e";
discounts["success-20002"] = "f";
var discounted = discounts[discountname];
parent.frames['content'].location= "products" + discounted + ".html";
}
//-->
</script>
HWG hwg-techniques mailing list archives,
maintained by Webmasters @ IWA
This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.