Php code that verifies the validity and correctness of the email address entered by the user
Function validate_email ($ email ){
- $ Exp = "^ [a-z '0-9] + ([. _-] [a-z '0-9] +) * @ ([a-z0-9] + ([. _-] [a-z0-9] +) + $ ";
- If (eregi ($ exp, $ email) {// use a regular expression to verify the validity of the email format
- If (checkdnsrr (array_pop (explode ("@", $ email), "MX") {// use checkdnsrr to verify the validity of the email domain
- Return true;
- } Else {
- Return false;
- }
- } Else {
- Return false;
- }
- }
// Note: The checkdnsrr function is invalid on the win host! The following is a solution proposed by a foreign programmer. In addition, a function is written to replace the checkdnsrr function:
- Function myCheckDNSRR ($ hostName, $ recType = ''){
- If (! Emptyempty ($ hostName )){
- If ($ recType = '') $ recType =" MX ";
- Exec ("nslookup-type = $ recType $ hostName", $ result );
- Foreach ($ result as $ line ){
- If (eregi ("^ $ hostName", $ line )){
- Return true;
- }
- }
- Return false;
- }
- Return false;
- }
|