0

I'm looking to validate a credit card number using jQuery Credit Card Validator: http://jquerycreditcardvalidator.com/

For the past couple hours I've tried to familiarize myself with javascript, coffeescript, and jquery so I can figure out how to use it.

These are the steps i've taken to get it to work:

I downloaded coffeescript and node.js as well as jquery.

I compiled the .coffee file I downloaded from the credit card validator site above, which from what I understand turns it into plain Javascript.

Then I downloaded Sublime Text 2 and opened the new .js file and added script tags to the beginning and end.

Finally I saved it as a .html and tried to run it in chrome where nothing happens.

Forgive me if I'm missing something obvious or don't understand the concept, I believe what I'm trying to do is display the form at the top of the Credit Card Validator website above when I drag and drop the .html file into chrome, and from there I can validate my own credit card numbers.

So I'd imagine the "How to Use it section" on the website above is what I need to incorporate, but I have no clue how.

If someone could just point me in the right direction, you'd spare me hours of mindless tutorial surfing. Thanks

Edit: I used <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> and got rid of the jquery error, but now just a bunch of text appears and the syntax error mentioned in the comments.

8
  • Since you're in chrome, right-click and hit 'inspect element' -- you'll be able to see in the console if there are any errors. You'll probably need to reload the page with the console open.
    – ahren
    Mar 14, 2013 at 1:33
  • It says jquery is not defined. Mar 14, 2013 at 1:37
  • Right - so have you included jQuery? And included jQuery BEFORE your other scripts?
    – ahren
    Mar 14, 2013 at 1:42
  • I have a src= "the .js file that came from the website" at the beginning of the script I downloaded and compiled. Mar 14, 2013 at 1:51
  • <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="http://code.jquery.com/jquery-migrate-1.1.1.min.js"></script> before you load any libraries/scripts that depend on it
    – MattDMo
    Mar 14, 2013 at 17:56

1 Answer 1

0
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.2/jquery.validate.min.js" integrity="sha512-UdIMMlVx0HEynClOIFSyOrPggomfhBKJE28LKl8yR3ghkgugPnG6iLfRfHwushZl1MOPSY6TsuBDGPK2X4zYKg==" crossorigin="anonymous"></script>
<script src="http://igorescobar.github.io/jQuery-Mask-Plugin/js/jquery.mask.min.js"></script>

function ValidateCreditCardNumber() 
        {
            var ccNum = document.getElementById("creditcard").value;
            var visaRegEx = /^(?:4[0-9]{12}(?:[0-9]{3})?)$/;
            var mastercardRegEx = /^(?:5[1-5][0-9]{14})$/;
            var amexpRegEx = /^(?:3[47][0-9]{13})$/;
            var discovRegEx = /^(?:6(?:011|5[0-9][0-9])[0-9]{12})$/;
            var isValid = false;

            if (visaRegEx.test(ccNum)) 
            {
                isValid = true;
            } else if(mastercardRegEx.test(ccNum)) 
            {
                isValid = true;
            } else if(amexpRegEx.test(ccNum)) 
            {
                isValid = true;
            } else if(discovRegEx.test(ccNum)) 
            {
                isValid = true;
            }

            if(isValid) 
            {
                alert("Thank You!");
            } else 
            {
                alert("Please provide a valid Visa number!");
            }
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.