Skip to content

Add an 'alpha_numeric_punct' rule to FormatRules #2549

Description

@dafriend

A validation rule that allows alphanumerics, space and a limited set of punctuation characters.
The proposed set of punctuation chars are:
~ (tilde),
! (exclamation),
# (number),
$ (dollar),
% (percent),
& (ampersand),
* (asterisk),
- (dash),
_ (underscore),
+ (plus),
= (equals),
| (vertical bar),
: (colon),
. (period).

This rule would broaden the set of characters available for passwords.

Here's the proposed function definition

/**
 * Alphanumeric, spaces, and a limited set of punctuation characters.
 * Accepted punctuation characters are: ~ tilde, ! exclamation,
 * # number, $ dollar, % percent, & ampersand, * asterisk, - dash,
 * _ underscore, + plus, = equals, | vertical bar, : colon, . period
 * ~ ! # $ % & * - _ + = | : .
 *
 * @param string $str
 *
 * @return boolean
 */
public function alpha_numeric_punct($str)
{
        return (bool) preg_match('/^[A-Z0-9 ~!#$%\&\*\-_+=|:.]+$/i', $str);
}

I have a PR ready if this is, or could be made, agreeable.

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions