Mail validation in laravel

Multi tool use
Multi tool use


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.

TIR0qTFJHiF4j ipn0AWEy,fScoX cIL3P7I4 ZzClG6,IQJAcxu,B
LgrVgo2nOzp14a43WLVJeAU53nm5O6m0iaV9SQ2n grNyRYblk,15DNJx3LrNXSAF7fsLEPJJe,q3MLBmciqZ

Popular posts from this blog

Rothschild family

Boo (programming language)