Nazkyn Posted March 17, 2007 Share Posted March 17, 2007 How would I change the following script to strip the following characters from the user input - $,. <!--Beginfunction answer() {var emptyPocketsOne = document.calc.regex.value.match(/Empty Pockets: (\d*)/);var usedPocketsOne = document.calc.regex.value.match(/Used Pockets: (\d*)/); var labSpaceOne = document.calc.regex.value.match(/Drug Lab Size: (\d*)/);var junkiesOne = document.calc.regex.value.match(/Working Junkies: (\d*)/);var junkiesTwo = document.calc.regex.value.match(/Training Junkies: (\d*)/);var totalJunkiesOne = parseInt(junkiesOne[1]) + parseInt(junkiesTwo[1]);var coatOne = parseInt(usedPocketsOne[1]) + parseInt(emptyPocketsOne[1]);var emptyPocketsTwo = document.calc.regex.value.match(/Empty Pockets: (\d*)/);var usedPocketsTwo = document.calc.regex.value.match(/Used Pockets: (\d*)/);var labSpaceTwo = document.calc.regex.value.match(/Drug Lab Size: (\d*)/);var junkiesThree = document.calc.regex.value.match(/Working Junkies: (\d*)/);var junkiesFour = document.calc.regex.value.match(/Training Junkies: (\d*)/);var totalJunkiesTwo = parseInt(junkiesThree[1]) + parseInt(junkiesFour[1]);var coatTwo = parseInt(usedPocketsTwo[1]) + parseInt(emptyPocketsTwo[1]);var resultOne = 0;while (usedPocketsOne[1] > totalJunkiesOne - labSpaceOne[1] * 17) { resultOne = resultOne + 1; usedPocketsOne[1] = usedPocketsOne[1] - totalJunkiesOne + labSpaceOne[1] * 17; totalJunkiesOne = totalJunkiesOne + 1;}var resultTwo = 0;while (usedPocketsTwo[1] > totalJunkiesTwo - labSpaceTwo[1] * 17) { resultTwo = resultTwo + 1; usedPocketsTwo[1] = usedPocketsTwo[1] - totalJunkiesTwo + labSpaceTwo[1] * 17;}var visitsOne = document.calc.regex.value.match(/Dealer Visits Remaining: (\d*)/);if (visitsOne[1] == 0) { resultOne = resultOne - 2; usedPocketsOne[1] = usedPocketsOne[1] + 1;}var visitsTwo = document.calc.regex.value.match(/Dealer Visits Remaining: (\d*)/);if (visitsTwo[1] == 0) { resultTwo = resultTwo - 2; usedPocketsTwo[1] = usedPocketsTwo[1] + 1;}alert(resultOne);}// End--> Thanks in advance Link to comment Share on other sites More sharing options...
jesh Posted March 19, 2007 Share Posted March 19, 2007 How would I change the following script to strip the following characters from the user input -$,. If you have a string, you can replace characters in that string with the replace method. If you wanted to replace all "$", "," and "." characters, you could do it like so:var string = "This is a string. It's worth, I don't know, $4.00.";var newstring = string.replace(/[$,\.]/g, ""); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now