I have a value that I will want to add two hyphens.
For example, if I receive:
FN322KN
I want to transform it to:
FN-322-KN
I am trying to use this solution (Mask javascript variable value) and Im stuck here:
CODE:
var value = 'FN322KN';
var formatted = value.replace(/^(.{2})(.{5}).*/, '$1-$2');
RESULT KO:
'FN-322KN'
Can someone please tell me how I can add the second "-" ?
UPDATE!!
Both Mark Baijens and Buttered_Toast answers are correct. I have one more question though. What if the value comes like FN-322KN or F-N322-KN ? Like, out of format? Because if thats the case, then it adds one hifen where one already exists, making it "--".
Thanks!