Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert '-' every 5 characters as users type [like a product key] [duplicate]

Possible Duplicate:
Auto-format structured data (phone, date) using jQuery plugin (or failing that vanilla JavaScript)
Insert space after certain character into javascript string

I am trying to write a script that handles product keys like the ones you see on the back of software and games.

I would like so when the user is inputing their key code the '-' are inserted every 5 characters for 5 sets of characters. Ex(ABCDE-FGHIJ-KLMNO-PQRST-UVWXY). So when the user enters ABCDE as soon as the 'E' is enetered a '-' is inserted immeditly after via jQuery or JavaScript.

Thanks In Advance. Comment if you have any questions or if I was unclear :)

Form:

<form method="post" action="process.php">
<p>Key: <input name="key" id="key" size="40"></p>
<p><input type="submit"></p>
</form>
like image 730
Stephen Cioffi Avatar asked Dec 01 '22 21:12

Stephen Cioffi


1 Answers

You can use http://digitalbush.com/projects/masked-input-plugin/

jQuery(function($){
   $("#key").mask("aaaaa-aaaaa-aaaaa-aaaaa-aaaaa");
});
like image 105
Baba Avatar answered Dec 10 '22 13:12

Baba