php - how to make a patteren like 12345-1234567-8 using javascript or jquery? -


i need midify code mean after 5 character hyphen "-" auto inserted , after 7 character hyphen "-" inserted. in code after 5 character hyphen inserted.

<html> <head>       <script>             $('.creditcardtext').keyup(function() {           var foo = $(this).val().split("-").join(""); // remove hyphens           if (foo.length > 0) {             foo = foo.match(new regexp('.{1,5}', 'g')).join("-");           }           $(this).val(foo);         });       </script> </heead> <body>       <input type="text" class="creditcardtext" /> </body> </html> 

http://jsfiddle.net/juspc/126/

you can match whole string of numbers, , split them chunks this:

var num = "1234512345671";  alert("parsed: " + num.replace(/(\d{5})(\d{7})(\d)/, "$1-$2-$3"));


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -