0

i am new to laravel.. my problem is
i have a html form in which i am taking more than one phone number in a single input text tag using saprator ',' which is working fine.. but when i take that form data to controller i want to validate that each data should be a number and it should be of 10 digit only. same thing i want to do for the email also. i have use laravel validation for the same but its not working... can anyone please help me on this.. thanx in advance: This is my controller store method code : Controller Code :

    public function store(Request $request, Customer $newCustomer)
{
    $mobileNo[] = explode(',',$request->contactNo);
    $request->contactNo = $mobileNo;

    $emails[] = explode(',',$request->email);
    $request->email[] = $emails;

    Validate::newCustomer($request);
}

Validation code :

public static function newCustomer(Request $request)
{
    $request->validate([
        'companyName' => 'required|string',
        'city' => 'required|string',
        'contactNo' => 'required|array',
        'contactNo.*' => 'digits_between:10,10',
        'email' => 'required|email',
        'email.*' => 'email',
    ]);

}
  • 1
    Don't upload `emails` as a command separated string... Use a proper series of `` elements, and then use `'emails' => 'required|array'` and `emails.* => 'email'`. As for phone number, likely the same issue, but there isn't a built in validation for phone numbers. You'll need to use a `regex` rule for that. – Tim Lewis Sep 08 '20 at 15:45
  • https://stackoverflow.com/questions/36777840/how-to-validate-phone-number-in-laravel-5-2 . You can get the answer here. – Sohail Ansari Sep 08 '20 at 15:56
  • but how to use name ='emails[]' when we dont know how many emails will be entered.. that why i have used the ',' separator for the same – Kiran Vibhakar Sep 08 '20 at 16:44

0 Answers0