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 ?
https://laravel.com/docs/5.8/validation#rule-regex
Internally, this rule uses the PHP preg_match function. The pattern specified should obey the same formatting required by preg_match and thus also include valid delimiters. For example: 'email' => 'regex:/^.+@.+$/i'
@SNAPEY - I want to allow
abc
acx100
[email protected]
abc_100
that means. _ @ A-Z 0-9
what should be the regex? I tried but it is not working.
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 sign in or create an account to participate in this conversation.