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

JackD's avatar

alpha numeric and spaces validation

Hi guys, i tried alpha_num to validate and restrict input for letters and numbers but why is that spaces is not included?

regards ci

0 likes
8 replies
pmall's avatar
[
    'field' => 'regex:[a-zA-Z0-9\s]+',
]
JackD's avatar

@bestmomo tried it works but i also need the numeric to be accepted, what should i add to make it accept also the numeric input?

@pmall it gives me an error message

JackD's avatar

@pmall here is the error message i got

preg_match(): Unknown modifier '+'
pmall's avatar
[
    'field' => 'regex:/[a-zA-Z0-9\s]+/',
]
2 likes
JackD's avatar

@pmall it accepts special characters, i used this instead regex:/(^[a-zA-Z0-9 ]+$)+/

pmall's avatar

Cleaner :

[
    'field' => 'regex:/^[a-zA-Z0-9\s]+$/',
]
7 likes

Please or to participate in this conversation.