This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Numeric Regular Expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Numeric Regular Expression" Watch "Numeric Regular Expression" New topic

Numeric Regular Expression

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 815
Hi All,
Trying to get this regular expression working.

I'm trying to have a regular expression that takes a number to determine how many decimals it wants in $1 and the rest should go into $2. Basically I have a number like 35.69. I find the position of the decimal and then any 4 digit number a user enters has to be reformated to look like the number specified (in this case 35.69). What I'm trying to do is take the index of the decimal in 35.69 and then use it within the previously mentioned code to grab first N number of digits and put the rest into $2. Each time I run this I keep getting only the second digit in $1 (in this case 5.69, if Answer was 95.67 Answer would end up being 5.67, etc..,). Any help would be appreciated. Thanks in advance.

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 815
Sorry guys. Bracket wasn't on the other side of the braces.
It is sorta covered in the JavaRanch Style Guide.
subject: Numeric Regular Expression
Similar Threads
Validating user input: checking for illegal characters
Regular Expression for any number
Regular Expressions and JavaScript
How to format the number
Reguler expression to find #number