Home > Article > Backend Development > php verify email is correct
# Is the php verification email correct?
1: Verify the email address by bringing it in
eg: $result = filter_var('bob@example.com', FILTER_VALIDATE_EMAIL);
When printing the results , if the format is correct, the email address is output, if it is wrong, false
2 is output: Regular matching
(1) $regex= '/\w ([- .]\w )*@ \w ([-.]\w )*\.\w ([-.]\w )*/';
(2)$regex="/([a-z0-9]* [-_.]?[a-z0-9] )*@([a-z0-9]*[-_]?[a-z0-9] ) [.][a-z]{2,3}( [.][a-z]{2})?/i";
Both of the above two regular expressions can be used to match email addresses. The matching method is as follows:
$str = "email@example.com"; $result = preg_match($regex,$str);
If the email address is in the correct format, The result value is 1, and the error is false
PS: Paste the regular verification of landline and mobile phone numbers↓
$isTel="/^([0-9]{3,4}-)?[0-9]{7,8}$/"; $isMob="/^1[3-8]{1}[0-9]{9}$/";
For more PHP related knowledge, please visit PHP tutorial!
The above is the detailed content of php verify email is correct. For more information, please follow other related articles on the PHP Chinese website!