Sobes.tech
Junior — Middle

How can you verify the correctness of an entered email address?

sobes.tech AI

Answer from AI

The verification of the correctness of an entered email address is usually performed using regular expressions (regex), which check the format of the string.

Example of a simple regex for email validation:

let email = "example@mail.com"
let emailRegex = "^[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegex)
let isValid = emailTest.evaluate(with: email)

This example checks that the email contains:

  • characters before the @ sign
  • the @ sign
  • a domain name with a dot and at least two characters in the zone

For more strict validation, you can use specialized libraries or send a confirmation to the email.

How can you verify the correctness of an entered… - sobes.tech