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

jewelhuq's avatar

Need help regarding validation (Allow A-Z,0-9,_,@,.)

How can we write a regular expression that should only allow character, number, dot and @

Now our rules is as follow

'username' => 'required|unique:users|alpha_num|min:4|max:50',

How can we change it ?

0 likes
3 replies
jewelhuq's avatar

I think I found the solution: 'username' => ['required','unique:users','min:4','max:50','regex:/^[A-Za-z0-9.@+]*$/'],

https://regexr.com/ is a good tools for regular express test

Please or to participate in this conversation.