function webform_number_format_match in Webform 6.3
Same name and namespace in other branches
- 7.4 components/number.inc \webform_number_format_match()
- 7.3 components/number.inc \webform_number_format_match()
Validates if a provided number string matches an expected format.
This function allows the thousands separator to be optional, but decimal points must be in the right location.
Based on http://stackoverflow.com/questions/5917082/regular-expression-to-match-n....
3 calls to webform_number_format_match()
- _webform_render_number in components/
number.inc - Implements _webform_render_component().
- _webform_submit_number in components/
number.inc - Implements _webform_submit_component().
- _webform_validate_number in components/
number.inc - A Drupal Form API Validation function. Validates the entered values from number components on the client-side form.
File
- components/
number.inc, line 773 - Webform module number component.
Code
function webform_number_format_match($value, $point, $separator) {
return preg_match('/^(-? ?[1-9](?:\\d{0,2})(?:' . ($separator ? preg_quote($separator, '/') . '?' : '') . '\\d{3})*(?:' . preg_quote($point, '/') . '\\d*[0-9])?|0?' . preg_quote($point, '/') . '\\d*[1-9]|0)$/', $value);
}