Framework: AlphaDash validate rule.

Created on 25 Mar 2017  路  6Comments  路  Source: laravel/framework

  • Laravel Version: 5.4.15
  • PHP Version: 7.1.3
  • Database Driver & Version: MySQL 5.7.16

Description:

The alpha_dash validate rule which defined in Illuminate\Validation\Concerns\ValidatesAttributes@validateAlphaDash is using preg_match('/^[\pL\pM\pN_-]+$/u', $value) > 0

However, it will allow input when input is non-english, for example, typing "璞嗗瓙" in Chinese, it is a valid content.

I think it should remove "\pL" to allow any languages in regex rule.

Steps To Reproduce:

needs more info

All 6 comments

@ChiVincent steps to reproduce? is there any other validation rule on that filed or just alphadash?

app/Http/Controllers/TestController:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Validator;

class TestController extends Controller
{
    public function getIndex(Request $request)
    {
        $validator = Validator::make($request->query(), [
            'name' => 'alpha_dash',
        ]);

        dd($validator->fails());
    }
}

router/web.php

<?php

Route::get('/test', 'TestController@getIndex');

When I use test.app/test?name=aaa, it show false;

When I use test.app/test?name=aaa!, it show true;

When I use test.app/test?name=璞嗗瓙, it show false, however, the word "璞嗗瓙" should not an alpha-numeric character, should it?

however, the word "璞嗗瓙" should not an alpha-numeric character

Why not?

"Alphanumeric" doesn't just refer to Latin letters https://en.wikipedia.org/wiki/Alphanumeric

Alphanumeric is a combination of alphabetic and numeric characters, and is used to describe the collection of Latin letters and Arabic digits or a text constructed from this collection.
-- Alphanumeric Wikipedia

Although the merriam-webster said that "alphanumeric" may often additionally refer to other symbols (such as punctuation marks and mathematical symbols), in POSIX/C there are either 36 (A-Z + 0-9, case insensitive) or 62 (A-Z + a-z + 0-9, case-sensitive)

What rule definition of validation in Laravel use? Is merriam-webster dictionary or POSIX/C?

@ChiVincent you can create your own validation rule or override the current to meet your expectations if you want, this looks like an opinionated issue and keeping the discussion may lead us to nowhere :)

Closing this issue but will try to keep track if others shared your concern and reported the same thing as an issue.

Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YannPl picture YannPl  路  3Comments

felixsanz picture felixsanz  路  3Comments

Anahkiasen picture Anahkiasen  路  3Comments

kerbylav picture kerbylav  路  3Comments

ghost picture ghost  路  3Comments