특수문자 |
패턴 내용 |
예 |
해당 문자열 |
. |
임의의 한 문자 |
s.e |
sae, sbe, sce, ... |
* |
* 앞의 문자가 없거나 하나 이상인 문자열 |
s*e |
e, se, sse, ssse, ... |
+ |
+ 앞의 문자가 하나 이상인 문자열 |
s+e |
se, sse, ssse, ... |
? |
? 앞의 문자가 없거나 하나인 문자열 |
th?e |
te, the, ... |
^ |
^ 다음의 문자열로 시작되는 문자열 |
^the |
the girl, theater |
$ |
$ 앞의 문자열로 끝나는 문자열 |
bc$ |
abc, bc, wbc |
예) ^a?bc : bc 또는 abc로 시작되는 모든 문자열
^the$ : the
▶ [ ] : [ ] 안의 문자 중 하나의 문자
예) [ab]cd : acd 나 bcd 가 포함하는 문자열
[a-z] : 영문 소문자를 한 문자 포함하는 문자열
[0-9] : 숫자 하나를 포함하는 문자열
a[^bc]d : abd 와 acd를 제외한 a.d 와 일치하는 문자열
▶ { } : 앞에 있는 문자 또는 문자열의 개수
예) a{2}b : aab를 포함하는 문자열
a{2,}b : a가 최소 2개이상이고 b가 뒤따르는 문자열
a{1,3}b : a가 한 개에서 3개까지 이고 b가 뒤따르는 문자열
▶ ( ) : 문자들의 그룹화
예) a(bc){2} : a 뒤에 bc의 개수가 2인 문자열
▶ | : OR 연산자
예) he|she : he 나 she를 포함하는 문자열
(he|she)is : heis 나 sheis를 포함하는 문자열
▶ 문자클래스
[[:alpha:]] : 알파벳 문자중 하나를 의미; [a-zA-Z] 또는 [a-Z]와 동일한 표현
[[:digit:]] : 숫자 하나를 의미; [0-9]와 동일한 표현
[[:alnum:]] :알파벳 문자나 숫자중 하나를 의미; [a-zA-Z0-9]와 동일한 표현
[[:space:]] : 공백문자를 의미
■ 관련 PHP 함수
▶ ereg( string pattern, string string ) ~ 패턴에 대한 문자열이 존재하면 true를 반환
예)
ereg( "^[[:alpha:]][[:alnum:]]{0,7}$", $id )
▶ ereg_replace( string pattern, string replacement, string string)
: string 중에서 pattern과 일치하는 문자열을 replacement로 대치
■ Javascript를 이용한 form check
<head>
<script language=javascript>
function check_form(form) {
......
document.regform.submit();
}
function check_ID(ref) {
var id=eval(document.regform.id);
if (!id.value) { alert('아이디를 입력하고 확인하세요'); id.focus(); return;
}
else { ref = ref + "?id=" + id.value;
window.open(ref, "checkID", 'width=300,height=200,status=no');
}
}
</script></head>
<body>
<form name=regform method=post action="registration_process.php">
회원가입양식<p>
아이디 : <input type=text name=id maxlength=8><br>
(최대 8자리 Alphanumeric)
<input type="button" value="아이디 중복확인" onclick="check_ID('check_id.php')"><br>
.....
<p>
<input type=button value="회원가입" onclick="check_form(this.form)">
</form>
</body></html>
■ check_id.php
<?
include "include.connect.php";
$query = "select * from userdb where id = '$id'";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
if ($rows) echo("$id 는 등록된 아이디입니다");
else echo("$id 는 사용가능한 아이디입니다");
?>
<html>
<hr>
<input type=button onclick="self.close()" value="닫기">
</html>
■ registration_process.php
<?
if (!ereg("^[[:alpha:]][[:alnum:]]{0,7}$", $id) ) {
echo("아이디는 최대 8자리 영숫자로 구성됩니다");
exit;
}
......
"쇼핑몰·홈페이지·오픈마켓
블로그·페이스북·이메일 등의 각종 마케팅 글쓰기, 각종 광고, 영업, 판매, 제안서, 전단지 반응율 3배×10배 이상 높이는 마법의 8단계 공식" |
![]() |
☞자세히보기 |
|
|