Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

numeric validation  RSS feed

 
Michael Waserman
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found here many good examples of the numeric validation techniqe.
Most of the experts suggest parsing or valueOf withting a try-catch block.
I have one problem with this code and can't find a way around.
If the number entered has letter 'e' it's being parsed of valued as a legitimate number represented using exponent. I can not alow the users to enter letters withing the string. What the solution could be?

And the second question - what is better in terms of performance - to use try-catch or just write a static class that would check character by character inside the input string for being a digit.

Thanks. Mike.
 
Dmitry Melnik
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also check if the string matches your specific Regex pattern.
 
Michael Waserman
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dmitry,
My application is running under java 1.3. Is it available under 1.3?
Could you please provide a code example lets say for a four characters number that may or may not have a decimal point.

Thanks very much. mike.
 
Dmitry Melnik
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My application is running under java 1.3. Is it available under 1.3?

As a part of third-party library only. http://www.javaregex.com for example.

If it's the only place in your project you plan to use regex matching, I would not recommend messing with it

Could you please provide a code example lets say for a four characters number that may or may not have a decimal point.



Could be optimized for your needs, of course.
 
Michael Waserman
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dima,
Thanks a lot for the code sample and link.


Misha.
 
Dmitry Melnik
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome

BTW, I did not tell it explicitely in my last message, but regex matching is available in JDKs 1.4 and newer. Is there anything which prevents you from using it in this project?
 
Michael Waserman
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The server where my application resides has only Java 1.3.1 installed.
Also, I have to learn how to use regex matching - never used it before.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!