Skip to content
Advertisement

Format credit card number

How to format and validate a credit card number with spaces between each 4 digit while typing:

JavaScript

I have tried:

JavaScript

Please help

Advertisement

Answer

Try this:

JavaScript

Note: Check this for detailed information https://www.peterbe.com/plog/cc-formatter.

To restrict the user to enter number only:

Javascript Way

JavaScript

OR

JavaScript

HTML5 Way

JavaScript

jQuery Way

JavaScript

Note: Please check here to get more information about various key code.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement