Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

379
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda