Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

374
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!