Hello, help please, do the registration and I know that there is a function preg_match(); , but I do not know how to install the check.

Help make a check for the following:

  1. E-mail (well, a simple format test@test.ru)
  2. Login (English letters and numbers)

    1 answer 1

    You can do the following:

     <?php // Email $pattern = '/^[\w\d_.+-]+@[\w\d-]+.[\w]+$/'; $str = 'info@domain.com'; if(preg_match($pattern, $str)) echo 'Валидно<br />'; else echo 'Не валидно<br />'; // Login $pattern = '/^[az\d]+$/i'; $str = 'login432'; if(preg_match($pattern, $str)) echo 'Валидно<br />'; else echo 'Не валидно<br />'; 

    It should be taken into account that the regular expression for the email address is approximate, it is rather difficult to take into account all the nuances of the email (it will be possible to skip some exotic cases).

    • ex-parrot.com/~pdw/Mail-RFC822-Address.html so the regular schedule looks like this? - pavel
    • @pavel, aha, but in my opinion even RFC822 is outdated (needs to be checked). - cheops
    • For an electric ^[^\x00-\x1f\s]+@[^\x00-\x1f\s]+$ I would check like this ^[^\x00-\x1f\s]+@[^\x00-\x1f\s]+$ . Anyway, without confirmation through the letter, it does not make any sense. - Visman