473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to create a credit/debit card payment form with validation?

Hello, I am trying to create a Credit/debit card payment form with validation. I want my form to work something like when I enter the visa card details. it should detect visa and show VISA logo only and hide other companies logo. Kindly help.I tried this code snippet -

What I have tried:

I tried the code below javascript

Expand|Select|Wrap|Line Numbers
  1. $(function($) {
  2.   $('[data-numeric]').payment('restrictNumeric');
  3.   $('.cc-number').payment('formatCardNumber');
  4.   $('.cc-exp').payment('formatCardExpiry');
  5.   $('.cc-cvc').payment('formatCardCVC');
  6.   $.fn.toggleInputError = function(erred) {
  7.     this.parent('.form-group').toggleClass('has-error', erred);
  8.     return this;
  9.   };
  10.   $('form').submit(function(e) {
  11.     e.preventDefault();
  12.     var cardType = $.payment.cardType($('.cc-number').val());
  13.     $('.cc-number').toggleInputError(!$.payment.validateCardNumber($('.cc-number').val()));
  14.     $('.cc-exp').toggleInputError(!$.payment.validateCardExpiry($('.cc-exp').payment('cardExpiryVal')));
  15.     $('.cc-cvc').toggleInputError(!$.payment.validateCardCVC($('.cc-cvc').val(), cardType));
  16.     $('.cc-brand').text(cardType);
  17.     $('.validation').removeClass('text-danger text-success');
  18.     $('.validation').addClass($('.has-error').length ? 'text-danger' : 'text-success');
  19.   });
  20. });

HTML

Expand|Select|Wrap|Line Numbers
  1. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.payment/3.0.0/jquery.payment.min.js"></script>
  2. <div class="padding">
  3.     <div class="row">
  4.         <div class="container-fluid d-flex justify-content-center">
  5.             <div class="col-sm-8 col-md-6">
  6.                 <div class="card">
  7.                     <div class="card-header">
  8.                         <div class="row">
  9.                             <div class="col-md-6"> <span>CREDIT/DEBIT CARD PAYMENT</span> </div>
  10.                             <div class="col-md-6 text-right" style="margin-top: -5px;"> <img src="https://img.icons8.com/color/36/000000/visa.png"> <img src="https://img.icons8.com/color/36/000000/mastercard.png"> <img src="https://img.icons8.com/color/36/000000/amex.png"> </div>
  11.                         </div>
  12.                     </div>
  13.                     <div class="card-body" style="height: 350px">
  14.                         <div class="form-group"> <label for="cc-number" class="control-label">CARD NUMBER</label> <input id="cc-number" type="tel" class="input-lg form-control cc-number" autocomplete="cc-number" placeholder="•••• •••• •••• ••••" required> </div>
  15.                         <div class="row">
  16.                             <div class="col-md-6">
  17.                                 <div class="form-group"> <label for="cc-exp" class="control-label">CARD EXPIRY</label> <input id="cc-exp" type="tel" class="input-lg form-control cc-exp" autocomplete="cc-exp" placeholder="•• / ••" required> </div>
  18.                             </div>
  19.                             <div class="col-md-6">
  20.                                 <div class="form-group"> <label for="cc-cvc" class="control-label">CARD CVC</label> <input id="cc-cvc" type="tel" class="input-lg form-control cc-cvc" autocomplete="off" placeholder="••••" required> </div>
  21.                             </div>
  22.                         </div>
  23.                         <div class="form-group"> <label for="numeric" class="control-label">CARD HOLDER NAME</label> <input type="text" class="input-lg form-control"> </div>
  24.                         <div class="form-group"> <input value="MAKE PAYMENT" type="button" class="btn btn-success btn-lg form-control" style="font-size: .8rem;"> </div>
  25.                     </div>
  26.                 </div>
  27.             </div>
  28.         </div>
  29.     </div>
  30. </div>
Jun 30 '19 #1
2 1410
dev7060
636 Expert 512MB
Visa starts with the number 4 and MasterCard starts with 5. You need to extract the first value of the input field and store it in a variable. Then use condition checks and apply the CSS display: none; property to the rest of the elements that you want to hide.
Jul 2 '19 #2
gits
5,390 Expert Mod 4TB
those 'numbers' that you can use to identify paymentcards are called BIN (Bank Identification Number) and a list of them can be found here:

https://www.bincodes.com/bin-list/

since its not always only 1 specific number per card-type we usually speak of the BIN-Range.
Jul 2 '19 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Raj | last post by:
Hi I am developing a POS system for a retail business and I need to support accepting the credit and the debit cards. This authorization interface need to be integrated to the my POS...
7
by: Ray | last post by:
Hi all, I'm new to JavaScript and am trying to create a client side JavaScript form validation script. I'm doing ok with validating text input boxes but have a problem that I have not been able...
8
by: dougawells | last post by:
I'm not figuring this probably simple thing out. I've got a form that when submitted takes an action to a Perl script..."...formsubmit.pl". I want to be able to validate some fields, so put an...
2
by: this one | last post by:
I have the following code <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
5
by: Badis | last post by:
Hi, I would like know how to create a form that accept and process payment from e.g "credit card". how can do it!!? how this form will process the payment made from a customer account to...
8
by: gnewsgroup | last post by:
I have never done anything involving handling credit card payment online. I searched this forum a little bit, and found a few related questions. But, I am still not clear how the solutions they...
0
by: er695hammes | last post by:
crack debit card pin
2
by: amskape | last post by:
Dear pals, I am searching a payment gateway which can do Credit/Debit/Internet banking in a single system. Do you know any thing in current existing system . Let me know and advise Thanks anes
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.