|
 |
|
[PHP] ทำอย่างไรให้พอคลิกช่อง Textbox และเป็นสีเหลืองพอกรอกข้อมูลผิดเป็นสีแดง |
|
 |
|
|
 |
 |
|
พอจะมีโค้ดมั้ยครับ
คลิกช่อง Textbox และเป็นสีเหลืองพอกรอกข้อมูลผิดเป็นสีแดง
หรือไม่ก็ช่วยดูฟังชั่นพวกนี้ทีครับ
Code (PHP)
<script type="text/javascript" language="javascript1.5">
<!--
function isValid(variable)
{
var ValidChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var isValid=true;
var Char;
for (i = 0; i < variable.length && isValid == true; i++)
{
Char = variable.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
isValid = false;
}
}
return isValid;
}
function isValidNum(variable)
{
var ValidChars = '0123456789';
var isValid=true;
var Char;
for (i = 0; i < variable.length && isValid == true; i++)
{
Char = variable.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
isValid = false;
}
}
return isValid;
}
function checkID(id)
{
if(id.length != 13) return false;
for(i=0, sum=0; i < 12; i++)
{
sum += parseFloat(id.charAt(i))*(13-i);
}
if((11-sum%11)%10!=parseFloat(id.charAt(12)))
return false;
return true;
}
function validate(form)
{
/* game_first */
if(form.game_first.value == '')
{
inlineMsg('game_first','<strong>ผิดพลาด</strong><br />คุณยังไม่ได้กรอกชื่อในเกม', 10);
return false;
}
if(form.game_first.value.length < 4 || form.game_first.value.length > 8)
{
inlineMsg('game_first','<strong>ผิดพลาด</strong><br />ชื่อในเกม ต้องมีความยาว 4-8 ตัวอักษร', 10);
return false;
}
if(!isValid(form.game_first.value))
{
inlineMsg('game_first','<strong>ผิดพลาด</strong><br />ชื่อในเกม ต้องมีตัวอักษร a-z หรือ A-Z เท่านั้น', 10);
return false;
}
/* game_last */
if(form.game_last.value == '')
{
inlineMsg('game_last','<strong>ผิดพลาด</strong><br />คุณยังไม่ได้กรอกนามสกุลในเกม', 10);
return false;
}
if(form.game_last.value.length < 4 || form.game_last.value.length > 8)
{
inlineMsg('game_last','<strong>ผิดพลาด</strong><br />นามสกุลในเกม ต้องมีความยาว 4-8 ตัวอักษร', 10);
return false;
}
if(!isValid(form.game_last.value))
{
inlineMsg('game_last','<strong>ผิดพลาด</strong><br />นามสกุลในเกม ต้องมีตัวอักษร a-z หรือ A-Z เท่านั้น', 10);
return false;
}
/* password */
if(form.password.value == '')
{
inlineMsg('password','<strong>ผิดพลาด</strong><br />คุณยังไม่ได้กรอกรหัสผ่าน', 10);
return false;
}
if(form.password.value.length < 4 || form.password.value.length > 20)
{
inlineMsg('password','<strong>ผิดพลาด</strong><br />รหัสผ่าน ต้องมีความยาว 4-20 ตัวอักษร', 10);
return false;
}
/* repassword */
if(form.repassword.value == '')
{
inlineMsg('repassword','<strong>ผิดพลาด</strong><br />คุณยังไม่ได้กรอกยืนยันรหัสผ่าน', 10);
return false;
}
if(form.repassword.value.length < 4 || form.password.value.length > 20)
{
inlineMsg('repassword','<strong>ผิดพลาด</strong><br />ยืนยันรหัสผ่าน ต้องมีความยาว 4-20 ตัวอักษร', 10);
return false;
}
/* check password */
if(form.repassword.value != form.password.value)
{
inlineMsg('password','<strong>ผิดพลาด</strong><br />รหัสผ่าน และ ยืนยันรหัสผ่าน มีค่าไม่เหมือนกัน กรุณาตรวจสอบ', 10);
return false;
}
/* realname */
if(form.realname.value == '')
{
inlineMsg('realname','<strong>ผิดพลาด</strong><br />คุณยังไม่ได้กรอกชื่อจริง', 10);
return false;
}
/* lastname */
if(form.lastname.value == '')
{
inlineMsg('lastname','<strong>ผิดพลาด</strong><br />คุณยังไม่ได้กรอกนามสกุลจริง', 10);
return false;
}
/* pid */
if(!checkID(form.pid.value))
{
inlineMsg('pid','<strong>ผิดพลาด</strong><br />คุณยังไม่ได้กรอกรหัสบัตรประชาชน หรือ รหัสบัตรประชาชนไม่ถูกต้อง', 10);
return false;
}
/* sex */
if(form.sex[0].checked == false && form.sex[1].checked == false)
{
inlineMsg('sex','<strong>ผิดพลาด</strong><br />คุณยังไม่ได้เลือกเพศ', 10);
return false;
}
/* email */
var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
if(form.email.value == '')
{
inlineMsg('email','<strong>ผิดพลาด</strong><br />คุณยังไม่ได้กรอกอีเมลล์', 10);
return false;
}
if(!form.email.value.match(emailRegex))
{
inlineMsg('email','<strong>ผิดพลาด</strong><br />คุณกรอกอีเมลล์ไม่ถูกต้อง', 10);
return false;
}
/* age */
if(form.age.value == '')
{
inlineMsg('age','<strong>ผิดพลาด</strong><br />คุณยังไม่ได้กรอกอายุ', 10);
return false;
}
if(!isValidNum(form.age.value))
{
inlineMsg('age','<strong>ผิดพลาด</strong><br />คุณกรอกอายุไม่ถูกต้อง กรุณากรอกเฉพาะตัวเลขเท่านั้น', 10);
return false;
}
/* invite_code */
if(form.invite_code.value == '')
{
inlineMsg('invite_code','<strong>ผิดพลาด</strong><br />คุณยังไม่ได้กรอก รหัสเชิญชวน (Invite Code)', 10);
return false;
}
}
-->
</script>
จะเปิดใช้งานอย่างไรครับ ช่วยบอกที ใช้กับ textbox
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2010-08-29 08:45:52 |
By :
pepsikungza |
View :
1382 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 03
|