1

My project need to validate slug and Laravel does not handle Persian slug validator.So I have to use Regex.My slugs are like These:

/sony-صوتی-و-تصویری-15
/لباس-خوشگل-مجلسی
/songs-birds-15

I not found regex for pass this slugs. Do you have a solution?

6

1 Answer 1

0

In this example, it only accepts Persian letters An error is displayed if there are English letters

 $validate = Validator::make($request->all(), [
            'name' => 'required|regex:/^[\x{پچجحخهعغفقثصضشسیبلاتنمکگوئدذرزطظژؤإأءًٌٍَُِّ }]*$/u',

        ],
            [
                'name.regex' => 'نام باید به فارسی وارد شود',
            ]);
        if ($validate->fails()) {
            return [
                "status" => false,
                "error" => ['message' => $validate->errors()->messages()]
            ];
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.