troubleshooting Question

JS Script Crashing...

Avatar of mnb93
mnb93 asked on
Web Development
1 Comment1 Solution296 ViewsLast Modified:
I Found this by searching EE:

<form id="form1" name="form1" method="post" action="">
  <label for="price">Number
  <input type="text" name="price" id="price" onkeyup="numberMask(this)"/>

The code used for the mask function:

function numberMask(number)     {
     // remove all commas from the existing number
     number.value = number.value.replace(/,/gi,'');
     // add a comma to the first thousand
     number.value = number.value.replace(/(\d)(\d{3})$/gi,'$1,$2');
     // while there are four digits in a row, add a comma
     while(\d{4}/) >= 0)
          number.value = number.value.replace(/(\d)(\d{3},)/gi,'$1,$2');

Two Problems:

[Select All] Won't work. (+ I want a Clear Field button)
If I type 564894984984984/*4 The script crashes.
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros