Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 19th, 2005, 10:57 AM
Paul83 Paul83 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 1 Paul83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 43 sec
Reputation Power: 0
Question Regular Expressions

Hi, I need to create a regular expression in Java to accept floating point numbers.
These are the requirements that I have been given:

A floating point number consists of:
  • an optional sign ('+' or '- ')
  • an integer part (a sequence of digits)
  • an optional fractional part (a decimal point `.' followed by a sequence of digits)
  • an optional exponent part, consisting of
    • an exponent indicator (`e' or `E')
    • an optional sign (`+' or '-')
    • a non-empty sequence of digits
At least one of the digit sequences ``integer part'' or ``fractional part'' must be non-empty. The floating point number may not contain any spaces.

For example, all of the following are valid floating point numbers:
  • 56
  • 3.14159
  • -1e6
  • .5
  • 1.0E-6
The following are not valid floating point numbers:
  • 12E (empty exponent part)
  • e6 (empty integer and fractional part)
  • .e6 (empty integer and fractional part)
  • -+7 (two signs)
  • 23.-56 (sign in fractional part)
  • 2.13 E 25 (contains spaces)
Any replies much appreciated.
Thanks.

Reply With Quote
  #2  
Old March 19th, 2005, 01:41 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Hey Paul83!

Here's your regExp: ^[+|-]?[0-9]+(\.[0-9]+)?([eE][+|-]?[0-9]+)?$

This validates your examples. Although, you wrote an example that is not valid:

Quote:
Originally Posted by Paul83
  • .5



Anyway...hope this meets your requirements!

Good Luck!

ANibal.

Reply With Quote
  #3  
Old February 1st, 2007, 10:48 AM
ggavz ggavz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 3 ggavz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 35 sec
Reputation Power: 0
Could you recommend me a regex approach for this?

Hi everyone,

I have been asked to validate using REGEXP the following scenario:

V-123.456.789

Where:
1.- Either "V-" or "E-" always have to be at the beginning,
2.- The digits are an integer representation of a number from 1 to 999999999, using the "." as a 3 digits separator (if necessary as thousands representation).
3.- The digits cannot have leading zeros (0)

So, some valid entries could be:
V-1
E-1.234
V-12.345
V-1.234.567
V-123.456.789
V-123.012.345

Some invalid entries would be:
V-012.345.678
V-123456789
F-123.
E-1234.123

I have tried using the fol owing REGEXP but I don't think to be right:
^([VE]{1}\-)[0-9]+(.\d{3})* )?&

Any ideas...

Thanks

Reply With Quote
  #4  
Old February 1st, 2007, 11:55 AM
ggavz ggavz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 3 ggavz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 35 sec
Reputation Power: 0
Correction to original REGEXP...

Sorry, I made some typos. This is the one I have built so far:

^([VE]{1}\-)\d+(\.\d{3})*&

No spaces allowed either. Anyway, it doesn't seem to work.

Looking forward for any ideas...

Thanks

Reply With Quote
  #5  
Old February 1st, 2007, 01:02 PM
ggavz ggavz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 3 ggavz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 35 sec
Reputation Power: 0
Even closer, but not there yet...

This is closer to what I need, but still doesn't validate when no "." are used every three digits for thousands separation:

^[VE]{1}\-{1}[^0]{1}[0-9]+(\.[0-9]{3})*$

Still looking for your ideas...

Regards

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Regular Expressions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT