Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nav's avatar
Level 19

Regex Validation

Hi,

I dont use regex very often, so am not too familiar with it. I am trying to validate a input, and only want to allow a-z, A-Z, 0-9, spaces and a bunch of french characters. I dont want to allow < > quotes, script tags, etc..

Here is what i have:

'name' => ['required', 'regex:^[A-ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa-zàâçéèêëîïôûùüÿñæœ0-9_.,()]+$^']

Thing is, it works some times and not other. If you put < at the front of the data, it doesn't catch it. But catches it if its at the end.

Thanks.

0 likes
2 replies
SaeedPrez's avatar
Level 50

Try this..

'name' => ['required', 'regex:/^[A-ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa-zàâçéèêëîïôûùüÿñæœ0-9_.,() ]+$/']
5 likes
Nav's avatar
Level 20

Thank you, that did it.

1 like

Please or to participate in this conversation.