Home php Regular expression for complete check email

Regular expression for complete check email

Author

Date

Category

Tell me how to make a regular expression that:
Skip login email-a (up to @) in Russian or English with numbers or without or simply numbers.

Example of correct logins:
123456.
Login.
Login-1
Login.3.
login.3-67

Example of incorrect logins:
Loginlogin.
.123456.
123456 –

Domain (up to @) in English, with presence 1 or maximum 2 points:

Example of correct domains:
I.ru.
ru.name.ru

Example of incorrect domains:
.ru.
Ru
RU.
ru.name.ru.ua.
domain

Admissible length from 6 to 35 characters


Answer 1, Authority 100%

The required mask looks like this:
preg_match ('/ ^ ((([0-9a-za-z] {1} [- 0-9a-z \.] {1,} [0-9a-za-z] {1}) | ([0-9a-ya-i] {1} [- 0-9a-i \.] {1,} [0-9a-ya-i] {1})) @ ([- a-za- z] {1,} \.) {1,2} [- a-za-z] {2,}) $ / u ', $ item)

Spread the mask in more detail (please note that the mask broken into paragraphs does not work, it is done for readability)

'/
^ (- The parameter that the mask begins from the beginning of the text
  (
    (- This unit is responsible for Latin's login
      [0-9a-za-z] {1} - 1y character only digit or letter
      [-0-9a-z \.] {1,} - in the middle of at least one symbol (letter, digit, _, -,.) (At least 1 symbol)
      [0-9a-za-z] {1} - the last character of only a digit or letter
    )
    | - Parameter "or / or" Selects the Latin unit or "Cyril"
    (- This unit is responsible for the login of Cyril
      [0-9A-ya-i] {1} - 1y character only digit or letter
      [-0-9A-I \.] {1,} - in the middle of at least one character (letter, digit, _, -,.) (At least 1 symbol)
      [0-9a-ya-i] {1} - the last character of only a digit or letter
    )
  )
  @ - Vanity of the icon of a dividing login from the domain
  (
    [-0-9a-za-z] {1,} - block can consist of "-", numbers and letters (at least 1 symbol)
    \. - the presence of a point at the end of the block
  ) {1,2} - It is allowed from 1 to 2 blocks on the above mask (mail., Ru.mail.)
  [-A-za-z] {2,} - block Descriptive domain of the commander level (RU, COM, NET, AERO ETC) (at least 2 characters)
) $ - the parameter that the mask ends at the end of the text
/ U - the parameter allows you to work with Cyril
'

Source code feature with verification options:

& lt;? php
// ------ Correct.
$ email [] = '[email protected]';
$ email [] = '[email protected]';
$ email [] = '[email protected]';
$ email [] = '[email protected]';
$ email [] = '[email protected]';
$ email [] = '[email protected]';
$ email [] = '[email protected]';
// ----- WRONG.
$ email [] = '[email protected]';
$ email [] = '[email protected]';
$ email [] = '[email protected]';
$ email [] = '[email protected]';
$ email [] = '[email protected]';
$ email [] ='[email protected] ';
$ email [] = '[email protected]';
$ email [] = '@ 123456 @ I.ru';
$ email [] = '123456 @ .ru';
$ email [] = '123456 @ RU';
$ email [] = 'login @ .ru';
$ email [] = '[email protected]';
$ email [] = '[email protected]';
$ email [] = '[email protected]';
Foreach ($ email as $ item) {
  if (1 == preg_match (
    '/ =( ([0-9a-za-z [ 9a-yaaa] {1} [- 0-9a-I \.] {1,} [0-9a-ya-i] {1})) @ ([- 0-9a-za-z] { 1,} \.) {1,2} [- a-za-z] {2,}) $ / u ', $ item). '& lt; br / & gt;') {
    Echo '". $ item.'": Correct '. '& lt; br / & gt;';
  } else {
    Echo '". $ item.'": non-correct '. '& lt; br / & gt;';
  }
}

Answer 2

echo preg_match ('# ^ ([\ w] + \.?) + (? & lt;! \.) @ (?! \.) [A-ZA-Ya0-9, \ .-] + \.? [a-za-yay] {2,} $ # ui ','[email protected] .ru ');

Answer 3

This regularly:
1 – not let email with login less than 3 characters
2 – does not let email with a host more than 2nd subdomain
it will be better this way
^ ((([0-9a-za-z] {1} [- 0-9a-z \.] {0.30} [0-9a-za-z]?) | ([0- 9a-yaa] {1} [- 0-9a-i \.] {0.30} [0-9a-ya-i]?)) @ ([- a-za-z] {1,} \.) {1,} [- a-za-z] {2,}) $

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions