/** * 주민번호 유효성 검사 * @param $string $jumin */ function validate_jumin($jumin) { // 형태 검사: 총 13자리의 숫자, 7번째는 1..4의 값을 가짐 if (!preg_match('/^[0-9]{6}[1-4][0-9]{6}$/', $jumin)) return false; // 날짜 유효성 검사 $birthYear = ('2' >= $jumin[6]) ? '19' : '20'; $birthYear += substr($jumin, 0, 2); $birthMonth = substr($jumin, 2, 2); $birthDate = substr($jumin, 4, 2); if (!checkdate($birthMonth, $birthDate, $birthYear)) return false; // Checksum 코드의 유효성 검사 for ($i = 0; $i < 13; $i++) $buf[$i] = (int) $jumin[$i]; $multipliers = array(2,3,4,5,6,7,8,9,2,3,4,5); for ($i = $sum = 0; $i < 12; $i++) $sum += ($buf[$i] *= $multipliers[$i]); if ((11 - ($sum % 11)) % 10 != $buf[12]) return false; // 모든 검사를 통과하면 유효한 주민등록번호임 return true; } /** * select태그 생성 헬퍼 * @param string $name name/id * @param array $options option들 * @param string $select 선택값 * @return string */ function make_select($name, $options, $select = '', $desc = '선택', $tag = '') { $rtn = '<select name="'.$name.'" id="'.$name.'" '.$tag.'>'; if($desc !== NULL) $rtn .= '<option value="" '.(!$select?'select="select"':'').'>'.$desc.'</option>'; foreach($options as $key => $val) { $rtn .= '<option value="'.$key.'" '.((string)$key===(string)$select?'selected="selected"':'').'>'.$val.'</option>'; } $rtn .= '</select>'; return $rtn; } /** * 숫자셀렉트 * @param string $name name/id * @param int $syear * @param int $eyear * @param mixed $select * @param string $desc * @param string $tag * @return string */ function make_select_num($name, $snum, $enum, $select = NULL, $desc = NULL, $tag = '') { $rtn = '<select name="'.$name.'" id="'.$name.'" '.$tag.'>'; if($desc !== NULL) { $rtn .= '<option value="" '.(!$select?'select="select"':'').'>'.$desc.'</option>'; } for($i=$snum;$i<=$enum;$i++) { $rtn .= '<option value="'.$i.'" '.($i==$select?'selected="selected"':'').'>'.$i.'</option>'; } $rtn .= '</select>'; return $rtn; } /** * select 태그(telecom) 생성 헬퍼 * @param string $name name/id * @param string $select 선택값 * @return string */ function make_telecom($name, $select = '') { $options = array( 'SKT' => 'SKT', 'KTF' => 'KT', 'LGT' => 'LGT' ); $rtn = '<select name="'.$name.'" id="'.$name.'">'; $rtn .= '<option value="" '.(!$select?'select="select"':'').'>통신사</option>'; foreach($options as $key => $val) { $rtn .= '<option value="'.$key.'" '.((string)$key===(string)$select?'selected="selected"':'').'>'.$val.'</option>'; } $rtn .= '</select>'; return $rtn; }