php – Login check preg_match


Login validation regex required.

It is allowed to use only Latin letters, numbers, "-", "_" (line and underscore). The minimum amount of lat. letters – 4, maximum number of numbers – 4, underscores and dashes – 4.

My original line:

if( preg_match( "/[\||\'|\<|\>|\[|\]|\"|\!|\?|\$|\@|\#|\/|\\\|\&\~\*\{\+]/", $name ) )
  $stop .= $lang['reg_err_4'];

How can you correct it to meet all the conditions?


you can additionally introduce a limit on the number of characters, for example, from 6 to 12


so that you can't have two underscores in a row


so that there are no two underscores or minus in a row

Scroll to Top