0

I would like to know how can we validate the Credit Card.

We have a script that allows the numbers like this

4444111122223333

I want the credit card validation to accept credit card number in this format (with white spaces.)

4444 1111 2222 3333 

How it can be possible in JavaScript.

Thanks

A

user1089288
  • 99
  • 1
  • 5
  • 12
  • are you using any framework? such as jquery? if so, have a look at [some validation plugins](http://docs.jquery.com/Plugins/validation) – JMax Mar 26 '12 at 07:16
  • you don't need a framework. you just need to know the algorithm that makes a card number a valid card number (card numbers aren't like IDs that are "auto increment") – Joseph Mar 26 '12 at 07:18
  • Actually, we are using Jquery. but we are not focusing on the Credit Card types like Amex, Citibank, etc. etc. At the moment we are just focus on the validation with White spaces. – user1089288 Mar 26 '12 at 07:19
  • 1
    All you need to do is remove the spaces and pass it to your current validation, e.g. `num.replace(/\s/g,'');`. – RobG Mar 26 '12 at 08:14

2 Answers2

0

try this http://webwoman.biz/articles/Forms/NetscapeLibrary/ccnums.html

thecodedeveloper.com
  • 3,220
  • 5
  • 36
  • 67
  • Actually, we are using Jquery. but we are not focusing on the Credit Card types like Amex, Citibank, etc. etc. At the moment we are just focus on the validation with White spaces. – user1089288 Mar 26 '12 at 07:20
0

you could use regular expression to accomplish this task. take a look at this

and this short description of how to use regex in JavaScript

Helikaon
  • 1,490
  • 13
  • 30