How to validate an email address in PHP

The easiest and safest way to check whether an email address is well-formed is to use the filter_var() function: if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { // invalid emailaddress } Additionally you can check whether the domain defines an MX record: if (!checkdnsrr($domain, ‘MX’)) { // domain is not valid } But this still doesn’t guarantee that the … Read more

How should I validate an e-mail address?

Another option is the built in Patterns starting with API Level 8: public final static boolean isValidEmail(CharSequence target) { if (TextUtils.isEmpty(target)) { return false; } else { return android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches(); } } Patterns viewable source OR One line solution from @AdamvandenHoven: public final static boolean isValidEmail(CharSequence target) { return !TextUtils.isEmpty(target) && android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches(); }

C# code to validate email address

What about this? bool IsValidEmail(string email) { var trimmedEmail = email.Trim(); if (trimmedEmail.EndsWith(“.”)) { return false; // suggested by @TK-421 } try { var addr = new System.Net.Mail.MailAddress(email); return addr.Address == trimmedEmail; } catch { return false; } } Per Stuart’s comment, this compares the final address with the original string instead of always returning … Read more

What characters are allowed in an email address?

See RFC 5322: Internet Message Format and, to a lesser extent, RFC 5321: Simple Mail Transfer Protocol. RFC 822 also covers email addresses, but it deals mostly with its structure: addr-spec = local-part “@” domain ; global address local-part = word *(“.” word) ; uninterpreted ; case-preserved domain = sub-domain *(“.” sub-domain) sub-domain = domain-ref … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)