I am trying to validate a form which has phone number and we want that to be exactly 10 digits. But it gives errors even when the input is right I am using the following code in the controller so please advise as to what needs to be changed.
public function tytraining(Request $request)
{
$this->validate($request, [
'txt_name' => 'required',
'txt_email' => 'required|email',
'txt_phone' => 'required|numeric|between:9,11'
]);
$name = Input::get('txt_name');
$email = Input::get('txt_email');
$phone = Input::get('txt_phone');
$type = "bls-training";
$url = '?' . Input::get('url');
$medicalRequest = new ParseObject("MedicalRequest");
$medicalRequest->set("name", $name);
$medicalRequest->set("email", $email);
$medicalRequest->set("phone", $phone);
$medicalRequest->set("type", $type);
$medicalRequest->set("requestMessage", "training");
$medicalRequest->set("url", $url);
try {
$medicalRequest->save();
} catch (ParseException $ex) {
echo(' Some Error Occured');
}
}
Please advise how should I do the validation through Laravel..
Thank you all in advance for spending your valuable time and going through my concern and helping me out.
Validate Phone Number Laravel public function save(Request $request) { $validated = $request->validate([ phone_number=> 'required|numeric|min:10' ]); //If number passes validation, method will continue here. } In our save function we use the validate method provided by the Illuminate\Http\Request object.
Laravel includes a wide variety of convenient validation rules that you may apply to data, even providing the ability to validate if values are unique in a given database table.
use size and digits validation https://laravel.com/docs/5.3/validation#rule-digits
$this->validate($request, [
'txt_name' => 'required',
'txt_email' => 'required|email',
'txt_phone' => 'required|digits:10'
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With