Aristona
Aristona

Reputation: 9351

How can I add some single characters to my regex?

I need have a validation function for characters a-z, 0-9, _ and -. However I need some more single characters to this. Like ç, Ç, ş, Ş.

protected function validate_alpha_dash($attribute, $value)
{
    return preg_match('/^([-a-z0-9_-])+$/i', $value);
}

How should my pattern look like? I need to add like 10 more characters.

Upvotes: 1

Views: 68

Answers (1)

Jerska
Jerska

Reputation: 12002

Just add them between the brackets, making sure the - stays at the end of the character class:

protected function validate_alpha_dash($attribute, $value)
{
    return preg_match('/^([a-z0-9_çÇşŞ-])+$/i', $value);
}

Upvotes: 4

Related Questions