[9.x] Add alpha_num_ascii validation rule #45609
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
alpha_numrule 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
A(unicode: \uff21) or1(unicode: \uff11) may be accepted as input instead of half-width alphanumeric characters such asA(unicode: A) or1(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