diff --git a/docs/book/validators.md b/docs/book/validators.md index 6933653b..46870847 100644 --- a/docs/book/validators.md +++ b/docs/book/validators.md @@ -121,62 +121,3 @@ expression options. These include *Korean*, *Japanese*, and *Chinese*. As a result, when using the `Alpha` validator with these languages, the input will be validated using the English alphabet. - -## IsFloat - -`Laminas\I18n\Validator\IsFloat` allows you to validate if a given value contains a -floating-point value. This validator takes into account localized input. - -### Supported options - -The following options are supported for `Laminas\I18n\Validator\IsFloat`: - -- `locale`: Sets the locale to use when validating localized float values. - -### Basic float validation - -By default, if no locale is provided, `IsFloat` will use the system locale. - -```php -$validator = new Laminas\I18n\Validator\IsFloat(); - -$validator->isValid(1234.5); // returns true -$validator->isValid('10a01'); // returns false -$validator->isValid('1,234.5'); // returns true -``` - -(The above example assumes that the environment locale is set to `en`.) - -### Localized float validation - -Float values are often written differently based on the country or region. For -example, using English, you might write `1.5`, whereas in german you would write -`1,5`, and in other languages you might use grouping. - -`Laminas\I18n\Validator\IsFloat` is able to validate such notations. However, it is -limited to the locale you set. See the following code: - -```php -$validator = new Laminas\I18n\Validator\IsFloat(['locale' => 'de']); - -$validator->isValid(1234.5); // returns true -$validator->isValid("1 234,5"); // returns false -$validator->isValid("1.234"); // returns true -``` - -By using a locale, your input is validated based on the locale provided. Using a -notation not specific to the locale results in a `false` evaulation. - -The default validation locale can also be set after instantiation using -`setLocale()`, and retrieved using `getLocale()`. - -### Migration from 2.0-2.3 to 2.4+ - -Version 2.4 adds support for PHP 7. In PHP 7, `float` is a reserved keyword, -which required renaming the `Float` validator. If you were using the `Float` -validator directly previously, you will now receive an `E_USER_DEPRECATED` -notice on instantiation. Please update your code to refer to the `IsFloat` class -instead. - -Users pulling their `Float` validator instance from the validator plugin manager -receive an `IsFloat` instance instead starting in 2.4.0. diff --git a/docs/book/validators/is-float.md b/docs/book/validators/is-float.md new file mode 100755 index 00000000..3c6ac3ed --- /dev/null +++ b/docs/book/validators/is-float.md @@ -0,0 +1,67 @@ +# IsFloat + +`Laminas\I18n\Validator\IsFloat` allows you to validate if a given value +**contains a floating-point value**. This validator takes into account localized +input. + +Float values are often written differently based on the country or region. For +example, using English, you might write `1.5`, whereas in german you would write +`1,5`, and in other languages you might use grouping. + +`Laminas\I18n\Validator\IsFloat` is able to validate such notations. However, it +is limited to the locale you set. + +## Basic Usage + +```php +$validator = new Laminas\I18n\Validator\IsFloat(); + +$validator->isValid(1234.5); // true +$validator->isValid('10a01'); // false +$validator->isValid('1,234.5'); // true +``` + +By default, if no locale is provided, `IsFloat` will use the system locale +provided by PHP's `Locale` class and the `getDefault()` method. + +(The above example assumes that the environment locale is set to `en`.) + +Using a notation not specific to the locale results in a `false` evaluation. + +## Using Locale + +```php fct_label="Constructor Usage" +$validator = new Laminas\I18n\Validator\IsFloat(['locale' => 'en_US']); + +$validator->isValid(1234.5); // true +``` + +```php fct_label="Setter Usage" +$validator = new Laminas\I18n\Validator\IsFloat(); +$validator->setLocale('en_US'); + +$validator->isValid(1234.5); // true +``` + +```php fct_label="Locale Class Usage" +Locale::setDefault('en_US'); + +$validator = new Laminas\I18n\Validator\IsFloat(); + +$validator->isValid(1234.5); // true +``` + +### Get Current Value + +To get the current value of this option, use the `getLocale()` method. + +```php +$validator = new Laminas\I18n\Validator\IsFloat(['locale' => 'en_US']); + +echo $validator->getLocale(); // 'en_US' +``` + +### Default Value + +By default, if no locale is provided, `IsFloat` will use the system locale +provided by PHP's `Locale::getDefault()`. diff --git a/mkdocs.yml b/mkdocs.yml index c5d210e7..c4edb3e1 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -10,6 +10,7 @@ nav: - Validators: - 'Standard Validators': validators.md - DateTime: validators/date-time.md + - IsFloat: validators/is-float.md - IsInt: validators/is-int.md - PhoneNumber: validators/phone-number.md - PostCode: validators/post-code.md