JavaScript ง่ายๆ ไว้สำหรับ validate Form

Post a reply

Smilies
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: JavaScript ง่ายๆ ไว้สำหรับ validate Form

by 4404 » 06/07/2006 3:28 pm

icphysics wrote:อันนี้เว็บ สอนเขียน javascript ครับ ท่าน
http://www.c-point.com/javascript_tutorial/jstutor.htm

by DtTvB » 24/06/2006 12:13 am

บุคคลทั่วไป wrote:if (form.form_password.value=="") {
หากผู้ใช้พิมพ์เว้นวรรคลงไป ก็จะผ่านครับ
วิธีที่ถูกต้องกว่า คือ if (form.form_username.value.replace(/\s+$/, "") == "") {

by icphysics » 24/05/2006 5:45 pm

valid date ให้อยู่ในรูปแบบ (mm/dd/yyyy):
<script type="text/javascript">
function checkdate(input){
var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
var returnval=false
if (!validformat.test(input.value))
alert("Invalid Date Format. Please correct and submit again.")
else{ //Detailed check for valid date ranges
var monthfield=input.value.split("/")[0]
var dayfield=input.value.split("/")[1]
var yearfield=input.value.split("/")[2]
var dayobj = new Date(yearfield, monthfield-1, dayfield)
if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
else
returnval=true
}
if (returnval==false) input.select()
return returnval
}

</script>[
ตัวอย่าง Form
<form onSubmit="return checkdate(this.mydate)">
<input type="text" name="mydate" />
<input type="submit" value="submit" /><br />
<b>Valid date format:</b> mm/dd/yyyy
</form>;submit" value="submit">
</form>

by 4404 » 17/05/2006 4:00 pm

<script>
function checkForm() {
if (form.form_username.value=="") {
alert("Username not set");
return false;
}
if (form.form_password.value=="") {
alert("Password not set");
return false;
}
if (form.form_password2.value=="") {
alert("Password not set");
return false;
}
if (form.form_email.value=="") {
alert("E-Mail not set");
return false;
}
if (form.form_password.value!==form.form_password2.value) {
alert("Passwords do not match!");
return false;
}
}
</script>

JavaScript ง่ายๆ ไว้สำหรับ validate Form

by icphysics » 08/05/2006 11:40 am

<script language="JavaScript">
function validForm(passForm) {
if (passForm.username.value.replace( /\s+$/, "" )=="")
{
alert("กรุณาใส่ชื่อสมาชิก/Please enter your username" );
passForm.username.focus();
return false;
}
if (passForm.password.value.replace( /\s+$/, "" )=="")
{
alert("กรุณาใส่รหัสผ่าน/Please enter your password" );
passForm.password.focus();
return false;
}
return true;
}

//-->

</script>

Top