credit card validation using jquery

The code is not validating the values correctly, when i put in a simple digit it is already triggering the code.

$(".validate-card-num").live('keypress', function() { var ccNum = $(this).val(); //var visa = /^4[0-9]{12}([0-9]{3})?$/; //var master = /^5[1-5]([0-9]{14})$/; if(ccNum.test(/^4[0-9]{12}([0-9]{3})?$/)){ $("#img-visa").css("opacity","1"); $("#img-master").css("opacity","0.3"); }else if(ccNum.test(/^5[1-5]([0-9]{14})$/)){ $("#img-master").css("opacity","1"); $("#img-visa").css("opacity","0.3"); }else $("#img-master, #img-visa").css("opacity","0.3") });

for example i put in "5" the value triggers the regex but when i put in another value it disables the regex all together.

-------------Problems Reply------------

You are not using the .test() function correctly. This function is only available in RegExObject, and you are using it on a string. Your code should be like this:

var ccNum = "Test CC";
var visa = new RegExp("Paste Your Visa Pattern Here");
//Then do the check
if(visa.test(ccNum)){
console.log('visa card');
}else{
console.log('not visa card');
}

Category:jquery Views:0 Time:2014-01-08

Related post

  • Credit Card validation with Jquery 2009-11-06

    I'm trying to validate credit card numbers with jQuery but i dont want to use the validation plugin , is there any other plugin for doing this? --------------Solutions------------- http://en.wikipedia.org/wiki/Luhn%5Falgorithm You could minimize this

  • Is 42 a valid credit card number? jQuery validator thinks it is 2009-12-08

    We all know that 42 is the answer to everything, but it's news to me that it is a valid credit card number. Try entering '42' or '42176' into this jQuery Validation testing page and click OK. What's going on? I thought this was supposed to be the de-

  • Credit Card validation in Zend Framework 2008-09-16

    I'm trying to figure out how to detect the type of credit card based purely on its number. Does anyone know of a definitive, reliable way to find this? --------------Solutions------------- The credit/debit card number is referred to as a PAN, or Prim

  • Credit card validation with not working in Wordpress 2014-05-01

    I am using jQuery Credit Card Validation Plugin: Smart Validate to validate credit cards. It is working fine, when downloaded it and implemented in my localhost. But when I tried to implement the same in wordpress it is not working and when I checked

  • Credit Card Validation Resource for UK merchant 2009-08-27

    I'm trying to set the credit card numbers based on the standard check parameters but I am finding lots of UK cards (Maestro / Visa Debit / Barclaycard Connect) have start numbers that don't meet other card validation script regexes; I.e Maestro (Swit

  • Paypal credit card validation 2010-03-08

    I want to check that the credit card number provided by customer to my site is valid or not for further transaction. for that i wand to only verify taht the CC no is valid or not by Paypal. A method for that can be with paypal api step 1: DoDirectPay

  • Credit card validation and parsing utilities for .Net Compact framework 3.5 2010-05-27

    I have payment gateway integration in my application developed using .Net Compact framework 3.5. Is there any "Credit card validation and parsing utilities" that i can use in my application or is there any class that i can use to identify the type of

  • Credit card validation with regexp using test() 2011-02-06

    I'm trying to complete some homework and it appears the book might have gotten it wrong. I have a simple html page that allows user to pick a credit card in our case american express. The user then enters a number and evalutes that number based on a

  • Credit Card Validation Algorithm in iPhone Sdk 2011-10-19

    Can anyone please share any sample code for Credit Card Validation Algorithm. --------------Solutions------------- Luhn Algorithm: http://en.wikipedia.org/wiki/Luhn_algorithm Here some samples for common languages: http://rosettacode.org/wiki/Luhn_te

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.185 (s). 11 q(s)