This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.

I would like to come up with some regular expressions to validate numeric form data. I'd like to validate numbers, percentages, and currency values along with validating the range of those numbers.

For example, assume I have the following percentage input:

and the following function:

Can someone help me with coming up with a regular expression to normalize the value? An explanation of the regex would also be helpful because the currency validation is going to be a pain because of the vast array of currencies supported. Thanks in advance.

EDIT: Here are the requirements that I came up with: // expression starts with zero or one - character // the next 1 to n characters must be numbers // next, the text can contain zero or one instances of (a decimal separator followed by 1 to n numbers) // expression ends with zero or one % character // for an input of 12.5% or 12.5 I would like to get match to return 12.5 // if the input is 12.45 I can do the rounding after the normalizing

I figured out the regEx, but I'm having trouble getting match to be 12.5 if 12.5% is entered. Here is the regex and code: var value = "12.5%"; var regEx = /^(-)?(\d)+(\.(\d)+)*(%)?$/; var match = regEx.exec(value); alert(regEx.test(value)); for (var i = 0; i < match.length; i++) { alert(match[i]); } [ October 18, 2007: Message edited by: Dom Lassy ] [ October 18, 2007: Message edited by: Dom Lassy ]

You're close. The first '+' should be a '*' to account for numbers like '0.5', and the '*' should be a '?' because a number can only have a single decimal point.