Skip to content

Instantly share code, notes, and snippets.

@MajideND
Created April 11, 2021 07:09
Show Gist options
  • Save MajideND/15447ae5dd17ad4060254f5946ced9df to your computer and use it in GitHub Desktop.
Save MajideND/15447ae5dd17ad4060254f5946ced9df to your computer and use it in GitHub Desktop.
Laravel Iranian mobile number Validation (ساخت validation شماره همراه در لاراول)
//use this code in your function:
use App\Verification;
use Symfony\Component\HttpFoundation\Response;
$messages = [
'number.required' => 'شماره تلفن الزامی است',
'number.unique' => 'شماره تکراری است لطفا وارد شوید.',
'number.regex' => 'فرمت شماره شما صحیح نیست',
];
$validation = Validator::make($request->all(), [
'number' => 'required|unique:users,number|regex:/[0]{1}[0-9]{10}/'
], $messages);
if ($validation->fails()) {
$errors = $validation->errors();
return response()->json([
'status' => false,
'errors' => $errors
], Response::HTTP_UNPROCESSABLE_ENTITY, [
'Content-Type' => 'application/json; charset=UTF-8',
'charset' => 'utf-8'
], JSON_UNESCAPED_UNICODE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment