|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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:
For example, all of the following are valid floating point numbers:
Thanks. |
|
#2
|
|||
|
|||
|
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:
Anyway...hope this meets your requirements! Good Luck! ANibal. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Regular Expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|