Requires regular login validation expression.

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

My original line is:

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

How can I fix it to meet all the conditions?

  • Is it possible to determine the maximum number in the regular season if they are not in a row? Or was it meant just the same successive numbers and signs? login ya12---misha--224potapov---666 validin or not? - Alexey Shimansky
  • theoretically, you can choose 4 and look ahead, that there is no such sign. But the expression will be such that the computer will deal with it for half an hour. It is much more correct to select valid symbols, and count the number of each group as functions for working with strings - splash58

1 answer 1

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

 /([A-Za-z\d\-_]){6,12}/ 

That it was impossible to underline two consecutive

 ^([A-Za-z\d\-]|_(?!_)){6,12}$ 

so that two underscores or minuses cannot be

 ^([A-Za-z\d]|_(?!_)|\-(?!\-)){6,12}$ 
  • Thank you so much - Frenlion
  • Yes, there is not much for that - everything is quite simple :) - splash58
  • Can you help me a little more if you don’t bother you? - Frenlion
  • Can this expression? "/ ([A-Za-z \ d \ -_]) /" Add the following: so that underscores cannot be joined. Well, that is, the login for example, Fren__lion, would no longer be correct, but Fren_L_i_oN would be correct. - Frenlion
  • I updated the answer. and, by the way, a good style is to accept the answer, if it is correct, by clicking on the checkbox to the left of the answer. And when the rating of yours grows up, also press the arrow up :) - splash58