Javascript regex for product-key format

vipzeus

Member
Hi everybody,
finaly after a long time i'm back to work :)

I have a field where user must put some code and with follow javascript code i have the keystring to uppercase on keyup event.
Code:
this.update( this.getValue().toUpperCase() );
I need to have the dashes for each 5 chars like
XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
Where XXXXX is alphanumeric like microsoft licence code.
 
Hey!

Try ...

Code:
this.update( this.getValue().toUpperCase().replace(/(\d{5})(\d{5})(\d{5})(\d{5})(\d{5})/, "$1-$2-$3-$4-$5"));

-- hugh
 
You might want to put in a test for the length before that. But that should convert something which is definitely 25 digits long, with no spaces or other characters.

-- hugh
 
Hi Hugh! Its nice to hear you again :)
Your code works for numbers only as you wrote above.
I change the code as:
Code:
this.update( this.getValue().toUpperCase().replace(/([a-zA-Z0-9]{5})([a-zA-Z0-9]{5})([a-zA-Z0-9]{5})([a-zA-Z0-9]{5})([a-zA-Z0-9]{5})/, "$1-$2-$3-$4-$5"));
and work as i need.
The dashes are added only if all 25 chars fill the field.
Is there way to get dashes after 5 chars during digit and without have compltely all 25 chars?
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top