1

I have this password field on admin

enter image description here

But after upgrading php I got this error

preg_match(): Compilation failed: escape sequence is invalid in character class at offset 46

I have this validator pattern

 $rules = [
            'firstname' => 'required|max:255',
            'lastname' => 'required|max:255',
            'email' => 'required|email|unique:tblClient,fldClientEmail',
            'password' => 'required|min:8|regex:/^.*(?=.{1,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\X]).*$/'
        ];

is there changes needs to apply on my regex?

Note: original setup Laravel Framework version 5.1.46 (LTS) PHP 5.6

But Project Manager asks me to upgrade to PHP 7.4

Current setup as of now is Laravel Framework version 5.1.46 (LTS) php7.4

Pablo
  • 1,357
  • 1
  • 11
  • 40
  • Did you upgrade Laravel to a compatible version of PHP 7? – Arash Jul 28 '21 at 00:15
  • Just the php, Im using Laravel Framework version 5.1.46 (LTS) & upgraded to php 7.4 – Pablo Jul 28 '21 at 00:16
  • What version of Laravel are you using? – Arash Jul 28 '21 at 00:20
  • Current setup is Laravel Framework version 5.1.46 (LTS) and php 7.4 – Pablo Jul 28 '21 at 00:22
  • Laravel 5.5 or newer is recommended for PHP 7 https://laravel.com/docs/5.5/installation – Arash Jul 28 '21 at 00:25
  • 2
    Does this answer your question? [PCRE2 Regex error escape sequence is invalid in character class](https://stackoverflow.com/questions/64248370/pcre2-regex-error-escape-sequence-is-invalid-in-character-class) – HPierce Jul 28 '21 at 00:57
  • 1
    To summarize: you need to remove the `\X` in the regex. – HPierce Jul 28 '21 at 00:58
  • Follow @HPierce advice. As a side note: you should also update also the version of Laravel. It will save you a ton of headaches. You could use Laravel Shift to automate that. – Kenny Horna Jul 28 '21 at 01:37
  • For anyone who is not familiary with `\X` -- it matches (a single unicode grapheme](https://stackoverflow.com/a/55783469/2943403) – mickmackusa Nov 11 '22 at 00:24
  • `{1,}` can be reduced to `+`. If your pattern does not require case-sensitivity, use the `i` pattern modifier to avoid `[a-zA-Z]`. The first lookahead is redundant anyhow, because the other lookaheads require at least one character anyhow. `[0-9]` can be reduced to `\d`. I don't know what that last lookahead is trying to do, but maybe you mean to require a non-alphanumeric character? Probably better to try a negated character class for that. I don't know that those `.*` matches or the start/end anchors are necessary at all. (Note: I don't Laravel) – mickmackusa Nov 11 '22 at 00:27

0 Answers0