Design comparison
Solution retrospective
i used a library call Maska to split credit card number into 4 segments, do you have any better idea to format credit card number input?
Community feedback
- @simeydotmePosted over 2 years ago
You could consider setting a "pattern" attribute and "inputmode" attribute on the card number <input> so that it allows easier input on mobile devices :)
Aside from that the thing looks great! Good job! You've followed the design very well and the mobile view looks perfect!
0 - @blockfl0wPosted over 2 years ago
You can store the card number as string and then remove any extra whitespace potentially added by the user by using the
replace()
function I used this codenumber.value.replace(/\s/g, '');
. Then you can use theslice()
function to get the 4 segments of the value e.g.number.value.slice(0, 4);
This would get the first 4 numbers. Then repeat this 4 times to get each segment and from there you can do your validation0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord