Mail validation in laravel


Mail validation in laravel



I am trying to use laravel form validation.



My validation code is:


$this->validate(request(), [
'name' => 'required|alpha_num|max:255',
'email' => 'required|email|max:255|unique:users',
'register_no' => 'required|regex:/(1)[0-9]{3}-[0-9]{3}-[0-9]{3}/',
'password' => 'required|min:6'
]);



name takes everything whereas I want only letters & hyphen(-).
email takes gt@hj.fhdfygt@hj.fhdfy whereas I want like something@anything.com.
register_no says pattern doesn't match I wrote to return like 111-111-001.


name


email


gt@hj.fhdfygt@hj.fhdfy


something@anything.com


register_no


111-111-001





There already is an email validator in Laravel
– kerbholz
Jul 2 at 10:10




2 Answers
2



instead of alpha_num you can use regex (regular expression rule) for your custom formate like:


'name' => 'required|regex:/^[pLs-]+$/u',



the above is for alphabet without spaces you can create your own



u can use alpha_dash instead of alpha_num for name.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Rothschild family

Cinema of Italy