0

This is my LangRule file

<?php

namespace Modules\Newsletter\Rules;

use Illuminate\Contracts\Validation\Rule;

class LangRule implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
       

       return preg_match("/[^a-zA-ZÀ-ÿ.\-'_]*$/",$value);
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'Please select either English or French as your input language';
    }
}

I want to match English,French and .'-_ from input. My preg_match is not taking French characters. Can anyone help how I can do that. Help will be highly appreciated.

1 Answers1

1

You could use unicode properties:

preg_match("/^[a-zA-ZàâäèéêëîïôœùûüÿçÀÂÄÈÉÊËÎÏÔŒÙÛÜŸÇ]+$/", $string);
STA
  • 30,729
  • 8
  • 45
  • 59