-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Form] NumberType should display an error when a string is submitted #5707
Comments
Thank you for taking the time to report this issue! As you found out, NumberFormatter is the reason for this behavior. When #2059 is solved, this issue can probably be tackled as well. |
I've been struggling with this as well when a bad value is put in, like Would it be acceptable to at least throw an exception in |
@ericclemmons I cannot reproduce your issue. When I enter |
This is fixed in the referenced PR. |
This PR was merged into the master branch. Commits ------- c16d6bf [Form] Fixed NumberToLocalizedStringTransformer to throw an exception if numbers contain illegal characters Discussion ---------- [Form] Fixed NumberType to fail if numbers contain letters Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: #5707 Todo: - License of the code: MIT Documentation PR: -
Hello,
In Symfony 2.1.1, when a string such '1aaa' is input in a 'number' Form field, there is no validation error and the string value '1aaa' is converted in the numeric value '1'.
It looks like it is due to NumberFormatter in NumberToLocalizedStringTransformer.reverseTransform
a small php script which reproduces the conversion from string to numeric:
setAttribute(\NumberFormatter::FRACTION_DIGITS, 3); $formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, \NumberFormatter::ROUND_HALFUP); $formatter->setAttribute(\NumberFormatter::GROUPING_USED, false); return $formatter; } $formatter = getNumberFormatter(); $value = $formatter->parse('1aaa'); echo "Error Code:".$formatter->getErrorCode()."\n"; echo "intl_is_failure:".intl_is_failure($formatter->getErrorCode())."\n"; echo "is_numeric:".is_numeric($value)."\n"; echo $value; => Error Code:0 intl_is_failure: is_numeric:1 1 Best regards, ChristopheThe text was updated successfully, but these errors were encountered: