This parser implements the syntax defined by the HTML Standard for
valid floating-point numbers, which is used by elements such as
<input type="number">. The accepted syntax differs from both
Java number literals and JavaScript numeric literals.
In particular:
- only ASCII digits (
0-9) are accepted, - hexadecimal, binary, and octal notation are not supported,
NaNandInfinityare rejected, and- leading or trailing whitespace is not permitted.
- Author:
- Ronald Brill
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanReturns whether the supplied string is a valid HTML floating-point number.static BigDecimalParses the supplied string as an HTML floating-point number.
-
Method Details
-
isValid
Returns whether the supplied string is a valid HTML floating-point number.This method validates the complete input according to the HTML floating-point number grammar. A value is considered valid only if it can be parsed completely; partial matches are rejected.
- Parameters:
value- the string to validateacceptLeadingPlus- set this to true to accept strings like "+7"acceptDotAtEnd- set this to true to accept strings like "1."- Returns:
trueif the supplied string is a valid HTML floating-point number;falseotherwise- See Also:
-
parse
Parses the supplied string as an HTML floating-point number.If the input is syntactically valid, its numeric value is returned as a
BigDecimal. Otherwisenullis returned.This method performs syntax validation only. It does not apply any additional constraints that may be imposed by individual HTML algorithms or form controls.
- Parameters:
value- the string to parseacceptLeadingPlus- set this to true to accept strings like "+7"acceptDotAtEnd- set this to true to accept strings like "1."- Returns:
- the parsed value, or
nullif the supplied string is not a valid HTML floating-point number
-