troubleshooting Question

XJS: how to throw error if no match found

Avatar of badtz7229
badtz7229Flag for United States of America asked on
JavaScriptXML
8 Comments1 Solution211 ViewsLast Modified:
I have the following xml file that I am reading via xslt
<root>
      <test>
            <card>VI</card>
            <data>
                  <RegExp>^4[0-9]{12}(?:[0-9]{3})?$</RegExp>
                  <binExp>^[608623]{6}</binExp>
            </data>
      </test>
      <test>
            <card>MC</card>
            <data>
                  <RegExp>(?:^5[1-5]|^2[2-7])[0-9]{14}$</RegExp>
                  <binExp>^[542446]{6}</binExp>
            </data>
      </test>
</root>

Currently, I have logic where if the card number does not satisfy the RegExp then an error is thrown "Number is invalid"

However, I need to change my logic for a special case where if a VI number is entered that fails the RegExp but passes the binExp then DO NOT throw error all while still capturing error for other cards where it throws error if RegExp fails on them.

I had the following logic:

if (cardType != "VI" &&  (binExp && (binExp.test(cardNumber))) ) 
{

      if (RegExp && (!RegExp.test(cardNumber)))
            throw "Number is invalid";                        
      
}
           
but this won't work for an invalid MC. I want it throw error.
Example, I expect
5204730000001003 to pass
5704730000001003 to fail //but my logic doesn't throw error here. when it should.
ASKER CERTIFIED SOLUTION
Member_2_248744

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros