From f0c8d9cb163e6346e7fb04c663a482cf4d3af537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Bru=CC=88ckner?= Date: Mon, 16 Mar 2020 16:01:14 +0100 Subject: [PATCH 1/5] Adds new documentation for Alpha validator --- docs/book/validators/alpha.md | 80 +++++++++++++++++++++++++++++++++++ mkdocs.yml | 1 + 2 files changed, 81 insertions(+) create mode 100755 docs/book/validators/alpha.md diff --git a/docs/book/validators/alpha.md b/docs/book/validators/alpha.md new file mode 100755 index 00000000..f7819345 --- /dev/null +++ b/docs/book/validators/alpha.md @@ -0,0 +1,80 @@ +# Alpha + +`Laminas\I18n\Validator\Alpha` allows you to validate if a given value +**contains only alphabetical characters**. There is no length limitation for the +input you want to validate. This validator is identical to the +`Laminas\I18n\Validator\Alnum` validator with the exception that it does not +accept digits. + +## Basic Usage + +```php +$validator = new Laminas\I18n\Validator\Alpha(); + +if ($validator->isValid('Abcd')) { + // value contains only allowed chars +} else { + // false +} +``` + +## Using Whitespace + +By default, whitespace is not accepted as it is not part of the alphabet. +However, if you want to validate complete sentences or phrases, you may need to +allow whitespace; this can be done via the `allowWhiteSpace` option, either at +instantiation or afterwards via the `setAllowWhiteSpace()` method. + +```php fct_label="Constructor Usage" +$validator = new Laminas\I18n\Validator\Alpha(['allowWhiteSpace' => true]); + +if ($validator->isValid('Abcd and efg')) { + // value contains only allowed chars +} else { + // false +} +``` + +```php fct_label="Setter Usage" +$validator = new Laminas\I18n\Validator\Alpha(); +$validator->setAllowWhiteSpace(true); + +if ($validator->isValid('Abcd and efg')) { + // value contains only allowed chars +} else { + // false +} +``` + +### Get Current Value + +To get the current value of this option, use the `getAllowWhiteSpace()` method. + +```php +$validator = new Laminas\I18n\Validator\Alpha(['allowWhiteSpace' => true]); + +$validator->getAllowWhiteSpace(); // true +``` + +### Default Value + +The default value of this option is `false` that means whitespace characters are +not allowed. + +## Using different Languages + +When using `Laminas\I18n\Validator\Alpha`, the language provided by the user's +browser will be used to set the allowed characters. For locales outside of +English, this means that additional alphabetic characters may be used +— such as `ä`, `ö` and `ü` from the German alphabet. + +Which characters are allowed depends completely on the language, as every +language defines its own set of characters. + +Three languages supported by PHP's internationalization extension (`ext/intl`), +however, define multibyte characters, which cannot be matched as alphabetic +characters using normal string or regular 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. diff --git a/mkdocs.yml b/mkdocs.yml index 5dee557e..bce928da 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -9,6 +9,7 @@ nav: - Filters: filters.md - Validators: - 'Standard Validators': validators.md + - Alpha: validators/alpha.md - DateTime: validators/date-time.md - IsFloat: validators/is-float.md - IsInt: validators/is-int.md From f566d487072916d0495210c3b155b26a12b8f7f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Bru=CC=88ckner?= Date: Mon, 16 Mar 2020 16:02:13 +0100 Subject: [PATCH 2/5] Removes old documentation for Alpha validator --- docs/book/validators.md | 64 ----------------------------------------- 1 file changed, 64 deletions(-) diff --git a/docs/book/validators.md b/docs/book/validators.md index 46870847..4eb67493 100644 --- a/docs/book/validators.md +++ b/docs/book/validators.md @@ -57,67 +57,3 @@ languages therefore are unsupported with regards to the `Alnum` validator. When using the `Alnum` validator with these languages, the input will be validated using the English alphabet. - -## Alpha - -`Laminas\I18n\Validator\Alpha` allows you to validate if a given value contains -only alphabetical characters. There is no length limitation for the input you -want to validate. This validator is identical to the `Laminas\I18n\Validator\Alnum` -validator with the exception that it does not accept digits. - -### Supported options - -The following options are supported for `Laminas\I18n\Validator\Alpha`: - -- `allowWhiteSpace`: Whether or not whitespace characters are allowed. This - option defaults to `FALSE`. - -### Basic usage - -```php -$validator = new Laminas\I18n\Validator\Alpha(); -if ($validator->isValid('Abcd')) { - // value contains only allowed chars -} else { - // false -} -``` - -### Using whitespace - -By default, whitespace is not accepted as it is not part of the alphabet. -However, if you want to validate complete sentences or phrases, you may need to -allow whitespace; this can be done via the `allowWhiteSpace` option, either at -instantiation or afterwards via the `setAllowWhiteSpace()` method. - -To get the current state of the flag, use the `getAllowWhiteSpace()` method. - -```php -$validator = new Laminas\I18n\Validator\Alpha(['allowWhiteSpace' => true]); - -// or set it via method call: -$validator->setAllowWhiteSpace(true); - -if ($validator->isValid('Abcd and efg')) { - // value contains only allowed chars -} else { - // false -} -``` - -### Using different languages - -When using `Laminas\I18n\Validator\Alpha`, the language provided by the user's -browser will be used to set the allowed characters. For locales outside of -English, this means that additional alphabetic characters may be used -— such as `ä`, `ö` and `ü` from the German alphabet. - -Which characters are allowed depends completely on the language, as every -language defines its own set of characters. - -Three languages supported by ext/intl, however, define multibyte characters, -which cannot be matched as alphabetic characters using normal string or regular -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. From b606cc881f9237b8ebeb88af5e13ae6a35725eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Bru=CC=88ckner?= Date: Mon, 16 Mar 2020 20:29:22 +0100 Subject: [PATCH 3/5] Updates introduction for Alpha validator and adds link to Alnum --- docs/book/validators/alpha.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/book/validators/alpha.md b/docs/book/validators/alpha.md index f7819345..cc0f16c6 100755 --- a/docs/book/validators/alpha.md +++ b/docs/book/validators/alpha.md @@ -1,10 +1,9 @@ # Alpha `Laminas\I18n\Validator\Alpha` allows you to validate if a given value -**contains only alphabetical characters**. There is no length limitation for the -input you want to validate. This validator is identical to the -`Laminas\I18n\Validator\Alnum` validator with the exception that it does not -accept digits. +**contains only alphabetical characters**. This validator is identical to the +[`Laminas\I18n\Validator\Alnum` validator](alnum.md) with the exception that it +does not accept digits. ## Basic Usage From dea07fa47df5637f5f87a4a912562e78633623dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Bru=CC=88ckner?= Date: Tue, 17 Mar 2020 09:09:33 +0100 Subject: [PATCH 4/5] Updates if conditions in code examples of Alpha validator --- docs/book/validators/alpha.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/docs/book/validators/alpha.md b/docs/book/validators/alpha.md index cc0f16c6..e8b8c207 100755 --- a/docs/book/validators/alpha.md +++ b/docs/book/validators/alpha.md @@ -11,9 +11,7 @@ does not accept digits. $validator = new Laminas\I18n\Validator\Alpha(); if ($validator->isValid('Abcd')) { - // value contains only allowed chars -} else { - // false + // Value contains only allowed chars } ``` @@ -28,9 +26,7 @@ instantiation or afterwards via the `setAllowWhiteSpace()` method. $validator = new Laminas\I18n\Validator\Alpha(['allowWhiteSpace' => true]); if ($validator->isValid('Abcd and efg')) { - // value contains only allowed chars -} else { - // false + // Value contains only allowed chars } ``` @@ -39,9 +35,7 @@ $validator = new Laminas\I18n\Validator\Alpha(); $validator->setAllowWhiteSpace(true); if ($validator->isValid('Abcd and efg')) { - // value contains only allowed chars -} else { - // false + // Value contains only allowed chars } ``` From 7deeaa8a31a35b5b9996449b32230cc48512033e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Bru=CC=88ckner?= Date: Tue, 17 Mar 2020 09:10:35 +0100 Subject: [PATCH 5/5] Updates handling of return result in code example --- docs/book/validators/alpha.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/book/validators/alpha.md b/docs/book/validators/alpha.md index e8b8c207..ab579dcf 100755 --- a/docs/book/validators/alpha.md +++ b/docs/book/validators/alpha.md @@ -46,7 +46,7 @@ To get the current value of this option, use the `getAllowWhiteSpace()` method. ```php $validator = new Laminas\I18n\Validator\Alpha(['allowWhiteSpace' => true]); -$validator->getAllowWhiteSpace(); // true +$result = $validator->getAllowWhiteSpace(); // true ``` ### Default Value