A
A
Alexey Nikolaev2016-03-17 16:55:44
PHP
Alexey Nikolaev, 2016-03-17 16:55:44

How to properly write email validation?

Validation for the field Name (contact) is registered in the module controller

if ((utf8_strlen($this->request->post['contact']) < 3) || (utf8_strlen($this->request->post['contact']) > 100)) {
$json['error']['contact'] = $this->language->get('error_contact');
}

You need to add validation for the email field using a regular expression.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan, 2016-03-17
@0neS

php.net/manual/en/filter.examples.validation.php

if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
    echo "E-mail ($email_a) указан верно.";
}

Y
Yakov Vylegzhanin, 2016-03-17
@vylegzhanin

Googling once or twice.
Here is an interesting way, by the way, without regular expressions:

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // invalid emailaddress
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question