Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

373
Vistas
Validate Arabic Numbers in Laravel 5

I have a form that contains a field for user to enter amount value of certain payment. This field is input of type number.

The validation rule in Laravel for this input is:

'amount' => 'required|numeric'

When I enter the amount in English as: 1500 => The validation passes and everything is OK.

But when I enter the amount in Arabic as: ١٥٠٠ => The validation fails with the following error message:

"validation.numeric"

Should I validate this field manually or is there another solution to this problem?

error screenshot

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Maybe you can create your own validation type.

You can add something like this to your boot method in app/Providers/AppServiceProvider.php.

Validator::extend('arabic_numbers', function ($attributes, $value, $parameters, $validation) {
  $arabic_numbers = [
    '٥',
    '١',
    // add more
  ];

  $input = $value;
  if (!$input) {
    return false;
  }
  $chars = preg_split('//u', $input, -1, PREG_SPLIT_NO_EMPTY);
  foreach ($chars as $char) {
    if (!in_array($char, $arabic_numbers)) {
      return false;
    }
  }

  return true;
});

You can add to your existing rule, e.g. required|arabic_numbers.

Or use something like this:

$input = '١';
$validator = Validator::make([
    'user_input' => $input,
], [
    'user_input' => 'required|arabic_numbers'
];

if ($validator->fails()) {
    //
}

Also you can use in many other ways for example in a custom request:

public function rules()
{
    return [
        'something' => 'required|arabic_numbers',
    ];
}

Hope this helps.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda