JDK-6431200 : [Fmt-Nu] Provide a strict mode for NumberFormat
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 5.0,6
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-05-26
  • Updated: 2010-11-19
  • Resolved: 2010-11-19
Related Reports
Duplicate :  
Relates :  
NumberFormat is currently a bit leniant. It will parse '123xx' but not 'xx123'. Folks using JFormattedTextField that want number parsing use NumberFormat. It's not expected that either string would be valid, instead both should throw an exception. Obviously we can't change this now, so perhaps we could add an option to turn on strict parsing.

EVALUATION Developers can easily write code which checks if the given text includes an unexpected character before/after digits using ParsePosition and ParseException. I have no plan to add a method for the strict mode. *** (#1 of 1): [ UNSAVED ] ###@###.###

WORK AROUND Use a ParsePosition to get the index after parsing. If ParsePostion.getIndex() != string.length(), then parse() didn't consume the entire string.