urgent need help regarding formatting/parsing

  • Thread starter Thread starter CreativeMind
  • Start date Start date
C

CreativeMind

hi all,
i m using this function in javascript but there is problem.
function thousandseparator(val)
{
var regexpr=new RegExp('(-?[0-9]+)([0-9]{3})');
while(regexpr.test(val))
{
val=val.replace(regexpr,'$1,$2');
}
return val;
}
but it sometimes gives output as 1,2,345 while i use onblur and alert.
how can i resolve it?
how i change the string 123,456 into number 123456??
thx
 
Use split on the comma(s) and reconcatenate the data but the better solution
would be trying to refine the expression and not getting unwanted formatting
in the first place. I get upset with RegEx as it is not used frequently
enough and has to be relearned everytime it needs to be used. Good luck to
ya.
 
Back
Top