Form Validation

From: Date: Sat, 14 Oct 2000 21:27:34 +0000
Subject: Form Validation
Groups: php.general 
Request: Send a blank email to php-general+get-20170@lists.php.net to get a copy of this message
Hello. I have a form I am validating and I would like a little help. I can use strlen to find the length, but I need something that will tell me if A-Z or a-z is in the string. What function does this? I also am interested in a good email validator. So far I have found /* This function takes in an email address (say 'shane@tuna.org' and tests to see if it is a valid email address. An array with the results is passed back to the caller. Possible result codes for the array items are: Item 0: [true|false] true for valid email address false for NON-valid email address Item 1: [SMTP Code] if a valid MX mail server found, then fill this array in with failed SMTP reply codes Item 2: [true|false] true for valid mail server found for host/domain false if no valid mail server found Item 3: [MX server] if a valid MX host was found and connected to then fill in this item with the MX server hostname */ function validateEmail ( $email ) { global $SERVER_NAME; $return[0] = false; $return[1] = "Invalid email address (bad domain name)"; $return[2] = false; $return[3] = ""; list ( $user, $domain ) = split ( "@", $email, 2 ); $arr = explode ( ".", $domain ); $count = count ( $arr ); $bSuccess = false; for ( $i = 0; $i < $count - 1 && !$bSuccess; $i = $i + 1 ) { $domain = ""; for ( $j = $i; $j < $count; $j = $j + 1 ) { $domain = $domain . $arr[$j]; if ( $j < $count - 1 ) $domain = $domain . "."; } if ( checkdnsrr ( $domain, "MX" ) ) { if ( getmxrr ( $domain, $mxhosts, $weight ) ) { for ( $i = 0; $i < count ( $mxhosts ); $i++ ) { $fp = fsockopen ( $mxhosts[$i], 25 ); if ( $fp ) { $s = 0; $c = 0; $out = ""; set_socket_blocking ( $fp, false ); do { $out = fgets ( $fp, 2500 ); if ( ereg ( "^220", $out ) ) { $s = 0; $out = ""; $c++; $return[2] = true; $return[3] = $mxhosts[$i]; } else if ( ( $c > 0 ) && ( $out == "" ) ) { $return[2] = true; break; } else { $s++; } if ( $s == 9999 ) { break; } } while ( $out == "" ); set_socket_blocking ( $fp, true ); fputs ( $fp, "HELO $SERVER_NAME\n" ); $output = fgets ( $fp, 2000 ); fputs ( $fp, "MAIL FROM: <nobody@" . $SERVER_NAME . ">\n" ); $output = fgets ( $fp, 2000 ); fputs ( $fp, "RCPT TO: <$email>\n" ); $output = fgets ( $fp, 2000 ); if ( ereg ( "^250", $output ) ) { $return[0] = true; } else { $return[0] = false; $return[1] = $output; } fputs ( $fp, "QUIT\n" ); // close the file pointer fclose( $fp ); if ( $return[0] == true ) { $bSuccess = true; break; } } } } } } return $return; } Does this actually work, and how do I test it to see if the email address is valid or not? Thanks a lot!

« previous php.general (#20170) next »