Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
168
rated 0 times [  171] [ 3]  / answers: 1 / hits: 18746  / 7 Years ago, tue, december 26, 2017, 12:00:00

Help me to set credit card number format 1111-1111-1111-1111 like this in textbox field at insert time.



 <div class=form-group>
<label>Card Number</label>
<input type=text class=form-control placeholder=xxxx-xxxx-xxxx-xxxx name=card-number id=credit-card value= >
</div>
<div class=form-group center-block>
<input type=button name=btn-update id=btn-update value=UPDATE class=btn>
</div>

More From » php

 Answers
22

If you are using jquery





$('.creditCardText').keyup(function() {
var foo = $(this).val().split(-).join(); // remove hyphens
if (foo.length > 0) {
foo = foo.match(new RegExp('.{1,4}', 'g')).join(-);
}
$(this).val(foo);
});

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>

<input type=text class=creditCardText value=1234-1234-1234-1234 />




[#55596] Wednesday, December 20, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janettejordynm

Total Points: 550
Total Questions: 94
Total Answers: 98

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
janettejordynm questions
Tue, Nov 24, 20, 00:00, 4 Years ago
Sat, May 23, 20, 00:00, 4 Years ago
Mon, Apr 6, 20, 00:00, 4 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
;