S
S
Sergey2011-01-21 07:03:01
PHP
Sergey, 2011-01-21 07:03:01

How to validate fields with e-mail and phone in php?

What regular expression should be used and how to do it in PHP to check the correctness of e-mail and phone?

if $mail != $regexp?

Mail must be determined by the presence of a dog and a point.
phone by the presence of numbers and specials. characters (brackets, dashes and spaces are allowed, letters are not allowed)

Help, please, the site must be handed over in the morning, I did not sleep all night, now there is no time to learn.
I didn’t find anything good in Google, but maybe it’s just sleepy.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
Nodge, 2011-01-21
@butteff

Email verification:

if (preg_match('/[^(\w)|(\@)|(\.)|(\-)]/', $email))
  ...

Phone check:
if (preg_match('/((8|\+7)-?)?\(?\d{3,5}\)?-?\d{1}-?\d{1}-?\d{1}-?\d{1}-?\d{1}((-?\d{1})?-?\d{1})?/', $phone))
  ...

You can find almost any regular expression here .

R
Robotex, 2011-01-21
@Robotex

if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
die("Incorrect email!");

R
Robotex, 2011-01-21
@Robotex

Use filters. They are faster and simpler than regular expressions.

E
Eugene, 2015-07-06
@Eugeny1987

if (preg_match("/^[а-яА-Яa-zA-Z0-9_\.\-][email protected][а-яА-Яa-zA-Z0-9\-]+\.[а-яА-Яa-zA-Z\-\.]+$/Du", $email) > 0) {
  // to do
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question