Skip to content

Conversation

@fuwasegu
Copy link
Contributor

@fuwasegu fuwasegu commented Jan 11, 2023

The alpha_num rule must be used to validate that the field consists entirely of alphabetic and numeric characters.
However, in cultures such as Japan, where multibyte characters are used routinely, full-width alphanumeric characters such as (unicode: \uff21) or (unicode: \uff11) may be accepted as input instead of half-width alphanumeric characters such as A (unicode: A) or 1 (unicode: 1).
This can be converted to half-width alphanumeric characters programmatically, but it would be better if FormRequest could check it and return it as an error.

This PR implements a validation rule that checks for AlphaNum and single-byte alphanumeric characters (i.e., ASCII).

As an alternative, you can write regex:/^[a-zA-Z0-9]$/, but it would be easier to use if it is defined as a rule.

Usage

public function rules(): array
{
    return [
        'attribute_1' => ['alpha_num'], // 🙆‍♀ ABC123, 🙆‍♀ ABC123
        'attribute_2' => ['alpha_num_ascii'], // 🙆‍♀ ABC123, 🙅‍♀ ABC123
    ];
}

@taylorotwell
Copy link
Member

You can easily write a custom closure or class based rule for this. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants