anurag singh
anurag singh

Reputation: 3

How to write preg_match for english and french charaters?

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.

Upvotes: 0

Views: 85

Answers (1)

STA
STA

Reputation: 34678

You could use unicode properties:

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

Upvotes: 1

Related Questions