-
-
Save MajideND/15447ae5dd17ad4060254f5946ced9df to your computer and use it in GitHub Desktop.
Laravel Iranian mobile number Validation (ساخت validation شماره همراه در لاراول)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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