How to use js regular expressions to separate numbers with spaces every four digits
This article is about how js regular expressions enable numbers to be separated by spaces every four digits. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Code examples are separated by spaces every four digits of the number:
Share a code example that enables numbers to be separated by spaces every four digits.
This effect is very common when filling out bank cards, which is also a very humane measure.
The code example is as follows:
$(document) .ready (function () {$('# ant'). On ('keyup mouseout input', function () {var $this = $(this); var v = $this.val (); /\ s {5} / .test (v) & & $this.val (v.replace (/\ sCPG,'). Replace (/ (. {4}) / g, "$1");}) Thank you for reading! This is the end of the article on "how js regular expressions separate numbers with spaces every four digits". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!