Jump to content

Allow NUMBER as FIRSTNAME


Nicolased
 Share

Recommended Posts

Hi evryone, 

On prestashop 1.7.6, french, i have to made some overide ( or in core)

For link to business soft i need to allow Number in FIRST NAME and LAST NAME.

I find some trick who explain this:

Change Validate.php or change customer .php

I try to remove some characters  validate .php in line 182

  public static function isName($name) 
{
        $validityPattern = Tools::cleanNonUnicodeSupport(
            '/^(?:[^0-9!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u'
        );

 To :

 

  public static function isName($name)
    {
        $validityPattern = Tools::cleanNonUnicodeSupport(
            '/^*$/u'
        );

But  i still the same I can't creat new user with only number

I try this action:

, as not well Blank screen ...
I have to made a restore a backup...

 Does anyone now solution on prestashop 1.7.6.1?

thx for answer 🙂

 

 

 

 

 

Edited by Nicolased (see edit history)

Share this post


Link to post
Share on other sites

Nobody?

Work good on 1.7.4

I found difference between 1.7.4 and 1.7.6 .

In CUSTOMER.php, the field call "isCustomerName" not "isName" but problem stay the same.
Nothing append

-when i change "isCustomerName" ( in validate.php, remove 0-9)

When i change the field 

'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 255),

by isGenericName for test .

'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 255),

It's very strange,  because try on old 1.7.4 and it work like charm.

 

Very strange.

Share this post


Link to post
Share on other sites

Ok I

 find the solution:

 

Change validate.php in /classes/

 public static function isCustomerName($name)
    {
        $validityPattern = Tools::cleanNonUnicodeSupport(
            '/^0-9(?:[^!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u'
        );

        return preg_match($validityPattern, $name);
    }

To

 public static function isCustomerName($name)
    {
        $validityPattern = Tools::cleanNonUnicodeSupport(
            '/^(?:[^!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u'
        );

        return preg_match($validityPattern, $name);
    }

 

After:

You must have change 2 files:

in:

src/Core/Domain/Customer/ValueObject/

There is 2 files :

FirstName.php
LastName.php

 

change :

private function assertLastNameIsValid($lastName)
    {
        $matchesLastNamePattern = preg_match('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($lastName));

        if (!$matchesLastNamePattern) {
            throw new CustomerConstraintException(
                sprintf('Customer last name %s is invalid', var_export($lastName, true)),
                CustomerConstraintException::INVALID_LAST_NAME
            );
        }

By:

private function assertLastNameIsValid($lastName)
    {
        $matchesLastNamePattern = preg_match('/^[^!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($lastName));

        if (!$matchesLastNamePattern) {
            throw new CustomerConstraintException(
                sprintf('Customer last name %s is invalid', var_export($lastName, true)),
                CustomerConstraintException::INVALID_LAST_NAME
            );
        }

( In fact remove characters you want, for me only 1-9)

 

by the way , do the same with firstname:

  {
        $matchesFirstNamePattern = preg_match('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($firstName));

        if (!$matchesFirstNamePattern) {
            throw new CustomerConstraintException(
                sprintf('Customer first name %s is invalid', var_export($firstName, true)),
                CustomerConstraintException::INVALID_FIRST_NAME
            );
        }
    }

by

  {
        $matchesFirstNamePattern = preg_match('/^[^!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($firstName));

        if (!$matchesFirstNamePattern) {
            throw new CustomerConstraintException(
                sprintf('Customer first name %s is invalid', var_export($firstName, true)),
                CustomerConstraintException::INVALID_FIRST_NAME
            );
        }
    }

 

  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites

  • 9 months later...

Hello!

I created an account just to confirm that the above solution works.

I'm deploying version 1.7.6.7

Thank you!

Edit: it works until the customer attempts to edit their own profile, in case they wanted to add/modify their shipping address. In such case, the last name containing numbers becomes an issue. I am attempting to investigate and solve this...

PS_last name containing numbers.png

Edited by SomeUnknownGuy
added screenshot (see edit history)

Share this post


Link to post
Share on other sites

Okay, found solution.

In addition to the changes in Validate.php in /classes/, made by Nicolased, here:

On 9/24/2019 at 7:07 PM, Nicolased said:

Change validate.php in /classes/

 public static function isCustomerName($name)
    {
        $validityPattern = Tools::cleanNonUnicodeSupport(
            '/^0-9(?:[^!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u'
        );

        return preg_match($validityPattern, $name);
    }

To

 public static function isCustomerName($name)
    {
        $validityPattern = Tools::cleanNonUnicodeSupport(
            '/^(?:[^!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u'
        );

        return preg_match($validityPattern, $name);
    }

 

One more additional code modification is needed, in order to avoid name validation if the customer edits their own profile, to the same Validate.php file, in /classes/, as follows:

From:

public static function isName($name)
    {
        $validityPattern = Tools::cleanNonUnicodeSupport(
            '/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u'
        );

        return preg_match($validityPattern, $name);
    }

To:

public static function isName($name)
    {
        $validityPattern = Tools::cleanNonUnicodeSupport(
            '/^[^!<>,;?=+()@#"°{}_$%:¤|]*$/u'
        );

        return preg_match($validityPattern, $name);
    }

 

  • Like 1

Share this post


Link to post
Share on other sites

  • 1 month later...
On 9/24/2019 at 1:07 PM, Nicolased said:

Ok I

 find the solution:

 

Change validate.php in /classes/

 public static function isCustomerName($name)
    {
        $validityPattern = Tools::cleanNonUnicodeSupport(
            '/^0-9(?:[^!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u'
        );

        return preg_match($validityPattern, $name);
    }

To

 public static function isCustomerName($name)
    {
        $validityPattern = Tools::cleanNonUnicodeSupport(
            '/^(?:[^!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u'
        );

        return preg_match($validityPattern, $name);
    }

 

After:

You must have change 2 files:

in:

src/Core/Domain/Customer/ValueObject/

There is 2 files :

FirstName.php
LastName.php

 

change :

private function assertLastNameIsValid($lastName)
    {
        $matchesLastNamePattern = preg_match('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($lastName));

        if (!$matchesLastNamePattern) {
            throw new CustomerConstraintException(
                sprintf('Customer last name %s is invalid', var_export($lastName, true)),
                CustomerConstraintException::INVALID_LAST_NAME
            );
        }

By:

private function assertLastNameIsValid($lastName)
    {
        $matchesLastNamePattern = preg_match('/^[^!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($lastName));

        if (!$matchesLastNamePattern) {
            throw new CustomerConstraintException(
                sprintf('Customer last name %s is invalid', var_export($lastName, true)),
                CustomerConstraintException::INVALID_LAST_NAME
            );
        }

( In fact remove characters you want, for me only 1-9)

 

by the way , do the same with firstname:

  {
        $matchesFirstNamePattern = preg_match('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($firstName));

        if (!$matchesFirstNamePattern) {
            throw new CustomerConstraintException(
                sprintf('Customer first name %s is invalid', var_export($firstName, true)),
                CustomerConstraintException::INVALID_FIRST_NAME
            );
        }
    }

by

  {
        $matchesFirstNamePattern = preg_match('/^[^!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($firstName));

        if (!$matchesFirstNamePattern) {
            throw new CustomerConstraintException(
                sprintf('Customer first name %s is invalid', var_export($firstName, true)),
                CustomerConstraintException::INVALID_FIRST_NAME
            );
        }
    }

 

thank you ! 

 

this work for me in prestashop 1.7.6.7  !

for admin dashboard and front (user dashboard - update lastname and firstname)

Share this post


Link to post
Share on other sites

  • 1 month later...
  • 3 weeks later...
  • 2 months later...

First of all, thank you for your useful suggestion.

I've to add one more modification required to the code in order to allow to edit a customer from the BackOffice.

To complete the solution proposed by @Nicolased we have to make the following change inside the file:

/src/Core/ConstraintValidator/CustomerNameValidator.php

at the line 40, change the constant as follow

const PATTERN_NAME = '/^(?!\s*$)(?:[^!<>,;?=+()\/\\\\@#"°*`{}_^$%:¤\[\]|。]|[。\.](?:\s|$))*$/u';

Without this change, I can't edit and save a customer with numbers in firstname or lastname from the backoffice.

  • Like 1

Share this post


Link to post
Share on other sites

3 hours ago, antoniocici said:

First of all, thank you for your useful suggestion.

I've to add one more modification required to the code in order to allow to edit a customer from the BackOffice.

To complete the solution proposed by @Nicolased we have to make the following change inside the file:

/src/Core/ConstraintValidator/CustomerNameValidator.php

at the line 40, change the constant as follow

const PATTERN_NAME = '/^(?!\s*$)(?:[^!<>,;?=+()\/\\\\@#"°*`{}_^$%:¤\[\]|。]|[。\.](?:\s|$))*$/u';

Without this change, I can't edit and save a customer with numbers in firstname or lastname from the backoffice.

thank you for this update @antoniocici, is very important ! 

Share this post


Link to post
Share on other sites

  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More