Rimuru Tempest Asked: 2020-07-03 22:00:44 +0800 CST 2020-07-03 22:00:44 +0800 CST 2020-07-03 22:00:44 +0800 CST Allow special characters like @#%&-+()/*"':;!?|~{}[]_ in password 772 What regular expression can I use to allow characters like these @#%&-+()/*"':;!?~|{}[]_in php? php 1 Answers Voted Best Answer Jose Javier Segura 2020-07-03T23:48:42+08:002020-07-03T23:48:42+08:00 With this regular expression it forces you to: The password must be between 8 and 16 characters long, at least one digit, at least one lowercase, at least one uppercase, and at least one non-alphanumeric character. ^(?=.*\d)(?=.*[\u0021-\u002b\u003c-\u0040])(?=.*[A-Z])(?=.*[a-z])\S{8,16}$ the code in PHP if (preg_match('/^(?=.*\d)(?=.*[\u0021-\u002b\u003c-\u0040])(?=.*[A-Z])(?=.*[a-z])\S{8,16}$/', $cadenaok)) { return true; }
With this regular expression it forces you to:
The password must be between 8 and 16 characters long, at least one digit, at least one lowercase, at least one uppercase, and at least one non-alphanumeric character.
the code in PHP