Skip to content
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

Adds new documentation for Alpha validator #22

Merged
merged 5 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions docs/book/validators.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
73 changes: 73 additions & 0 deletions docs/book/validators/alpha.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Alpha

`Laminas\I18n\Validator\Alpha` allows you to validate if a given value
**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

```php
$validator = new Laminas\I18n\Validator\Alpha();

if ($validator->isValid('Abcd')) {
// Value contains only allowed chars
}
froschdesign marked this conversation as resolved.
Show resolved Hide resolved
```

## 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
}
froschdesign marked this conversation as resolved.
Show resolved Hide resolved
```

```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
}
```

### Get Current Value

To get the current value of this option, use the `getAllowWhiteSpace()` method.

```php
$validator = new Laminas\I18n\Validator\Alpha(['allowWhiteSpace' => true]);

$result = $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.
froschdesign marked this conversation as resolved.
Show resolved Hide resolved

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.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down