You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

42 lines
1.0 KiB

<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Validator;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Validator::extend('email_or_phone', function($attribute, $value, $parameters, $validator) {
// check email
if (filter_var($value, FILTER_VALIDATE_EMAIL)) {
return true;
}
// check phone
$phoneRegex = '/^[0-9]{9,11}$/'; // custom phone here
return preg_match($phoneRegex, $value);
});
Validator::replacer('email_or_phone', function($message, $attribute, $rule, $parameters) {
return str_replace(':attribute', $attribute, ':attribute phải là email hoặc số điện thoại hợp lệ.');
});
}
}