กำหนดตัวอักษรในช่อง php ได้ไม่เกิน กี่ตัว ทำยังไงค่ะ

เริ่มโดย Nato_One, 23 สิงหาคม 2012, 19:10:54

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

Nato_One

กำหนดตัวอักษรในช่อง php  ได้ไม่เกิน กี่ตัว ทำยังไงค่ะ 
<input name="no[]" id="no[]" type="text"/>
สามารถรับตัวอักษรได้ 5 ตัวได้ น้อยกว่า 5 ไม่ได้ หากมีตัวที่ 6 และ ไม่ถึงตัวที่ 10  ไม่สามารถ ผ่านได้ ขอคำแนะนำหน่อยค่ะ

comscizaa

งงกับคำถาม แต่คิดว่าน่าจะประมาณนี้ ใช้ javascript ทำเอาครับ

<script language="JavaScript" type="text/javascript">
function check() {
if(document.checkForm.post_detail.value.length < 5) {
alert("กรุณาระบุข้อความประกาศอย่างน้อย 5 ตัวอักษรครับ");
document.checkForm.post_detail.focus() ;
return false;
}
else if(document.checkForm.post_detail.value.length > 100) {
alert("กรุณาระบุข้อความประกาศไม่เกิน 100 ตัวอักษรครับ");
document.checkForm.post_detail.focus() ;
return false;
}
else
return true ; 
}
</script>

xvlnw.com

จขกท ใช้ name="no" ที่ไม่ใช้ no[] แล้วใช้โค๊ดข้างต้นได้เลยครับ
[direct=https://cloudhost.in.th/wordpress-hosting]ツ ⓌⓄⓇⒹⓅⓇⒺⓈⓈ ⒽⓄⓈⓉⒾⓃⒼ [/direct] :wanwan014:  :D
[direct=https://cloudhost.in.th/cloudhosting.html]Cloud Hosting[/direct] [direct=https://cloudhost.in.th/cloudvps.html]Cloud Server[/direct] [direct=https://cloudhost.in.th/vpshosting.html]Cloud VPS Hosting[/direct] [direct=https://cloudhost.in.th/windowsvps.html]Cloud Windows[/direct] Tel: 080-348-0843 LINE: ixvlnw

MeenyFancy

no[] ผมว่าเป็นเพราะเขาต้องการเป็น textbox array ครับ
ใช้ Code ตามนี้ครับ



<script language="javascript">
function fncSubmit()
{
for(i=1;i<=document.form1.hdnLine.value;i  )
{
if(eval("document.form1.txtName" i ".value.length") <5)
{
alert("incorrect format in box " i " Thank.");
eval("document.form1.txtName" i ".focus();")
return false;
}
}
document.form1.submit();
}
</script>
<form action="page.cgi" method="post" name="form1" onSubmit="JavaScript:return fncSubmit();">
Input 1 <input name="txtName[]" id="txtName1" type="text" maxlength ="10"><br>
Input 2 <input name="txtName[]" id="txtName2" type="text" maxlength ="10"><br>
Input 3 <input name="txtName[]" id="txtName3" type="text" maxlength ="10"><br>
Input 4 <input name="txtName[]" id="txtName4" type="text" maxlength ="10"><br>
Input 5 <input name="txtName[]" id="txtName5" type="text" maxlength ="10"><br>
<input type="hidden" name="hdnLine" value="5">
<input name="btnSubmit1" type="submit" value="Submit" >
</form>
Have a good trip.
[direct=http://petdeecare.com]สุนัขป่วย[/direct] [direct=http://petdeecare.com]แมวป่วย[/direct]
[direct=http://petdeecare.com]หนูป่วย[/direct] [direct=http://petdeecare.com]อาหารแมว[/direct] [direct=http://petdeecare.com]อาหารหมา[/direct]

Nato_One

อ้างถึงจาก: MeenyFancy ใน 23 สิงหาคม 2012, 19:29:37
no[] ผมว่าเป็นเพราะเขาต้องการเป็น textbox array ครับ
ใช้ Code ตามนี้ครับ



<script language="javascript">
function fncSubmit()
{
for(i=1;i<=document.form1.hdnLine.value;i  )
{
if(eval("document.form1.txtName" i ".value.length") <5)
{
alert("incorrect format in box " i " Thank.");
eval("document.form1.txtName" i ".focus();")
return false;
}
}
document.form1.submit();
}
</script>
<form action="page.cgi" method="post" name="form1" onSubmit="JavaScript:return fncSubmit();">
Input 1 <input name="txtName[]" id="txtName1" type="text" maxlength ="10"><br>
Input 2 <input name="txtName[]" id="txtName2" type="text" maxlength ="10"><br>
Input 3 <input name="txtName[]" id="txtName3" type="text" maxlength ="10"><br>
Input 4 <input name="txtName[]" id="txtName4" type="text" maxlength ="10"><br>
Input 5 <input name="txtName[]" id="txtName5" type="text" maxlength ="10"><br>
<input type="hidden" name="hdnLine" value="5">
<input name="btnSubmit1" type="submit" value="Submit" >
</form>

โทดนะค่ะ  copy code   มา ลอง รันไม่ได้ ค่ะ

rtee

ลองใช้ jQuery Validation สิครับ มันเช็คได้ว่าให้ minlength และ maxlength เท่าไหร่ ถ้าไม่เข้าเงื่อนไขก็ไม่ให้ผ่าน

ref. http://docs.jquery.com/Plugins/Validation

MeenyFancy

อ้างถึงจาก: Nato_One ใน 24 สิงหาคม 2012, 11:49:34
โทดนะค่ะ  copy code   มา ลอง รันไม่ได้ ค่ะ

งง ทำไมเครื่องหมาย   มันหายไปหว่า
<script language="javascript">
function fncSubmit()
{
for(i=1;i<=document.form1.hdnLine.value;i  )
{
if (eval("document.form1.txtName" i ".value.length") < 5 )
{
alert("incorrect format in box " i " Thank.");
eval("document.form1.txtName" i ".focus();")
return false;
}
}
document.form1.submit();
}
</script>



ไรนิ เครื่องหมาย บวก ไม่มา
Have a good trip.
[direct=http://petdeecare.com]สุนัขป่วย[/direct] [direct=http://petdeecare.com]แมวป่วย[/direct]
[direct=http://petdeecare.com]หนูป่วย[/direct] [direct=http://petdeecare.com]อาหารแมว[/direct] [direct=http://petdeecare.com]อาหารหมา[/direct]

Nato_One

อ้างถึงจาก: MeenyFancy ใน 25 สิงหาคม 2012, 10:15:42
อ้างถึงจาก: Nato_One ใน 24 สิงหาคม 2012, 11:49:34
โทดนะค่ะ  copy code   มา ลอง รันไม่ได้ ค่ะ

งง ทำไมเครื่องหมาย   มันหายไปหว่า
<script language="javascript">
function fncSubmit()
{
for(i=1;i<=document.form1.hdnLine.value;i  )
{
if (eval("document.form1.txtName" i ".value.length") < 5 )
{
alert("incorrect format in box " i " Thank.");
eval("document.form1.txtName" i ".focus();")
return false;
}
}
document.form1.submit();
}
</script>



ไรนิ เครื่องหมาย บวก ไม่มา

ถามต่ออีกนิดค่ะ  ทำแบบนี้ แล้ว code ไม่เข้า fnc
ทำแบบ array   ค่ะ โดย มี   name   id   แบบนี้ "no[]"    code ไม่เข้า fnc  ค่ะ  และมี   input   ประาณ 20 ช่อง สำหรับหารกรอกข้อมูลค่ะ
<input name="no[]" id="no[]" type="text"  size="10" maxlength ="13" />

MeenyFancy

อ้างถึงจาก: Nato_One ใน 26 สิงหาคม 2012, 23:13:38
ถามต่ออีกนิดค่ะ  ทำแบบนี้ แล้ว code ไม่เข้า fnc
ทำแบบ array   ค่ะ โดย มี   name   id   แบบนี้ "no[]"    code ไม่เข้า fnc  ค่ะ  และมี   input   ประาณ 20 ช่อง สำหรับหารกรอกข้อมูลค่ะ
<input name="no[]" id="no[]" type="text"  size="10" maxlength ="13" />


function ของภาษาอะไรครับ Java หรือ PHP คุณต้องเข้าใจก่อนว่า ID กับ Name มันใช้ต่างกันนะ
Have a good trip.
[direct=http://petdeecare.com]สุนัขป่วย[/direct] [direct=http://petdeecare.com]แมวป่วย[/direct]
[direct=http://petdeecare.com]หนูป่วย[/direct] [direct=http://petdeecare.com]อาหารแมว[/direct] [direct=http://petdeecare.com]อาหารหมา[/direct]

killer777

อ้างถึงจาก: rtee ใน 24 สิงหาคม 2012, 15:15:21
ลองใช้ jQuery Validation สิครับ มันเช็คได้ว่าให้ minlength และ maxlength เท่าไหร่ ถ้าไม่เข้าเงื่อนไขก็ไม่ให้ผ่าน

ref. http://docs.jquery.com/Plugins/Validation

ใช้ jquery ช่วย เร็วขึ้นเยอะเลยครับ