Regex form checking with Javascript -


i'm having real difficulty javascript.

what i'm trying validate user input html form.

i have 2 events html:

<form action="attendproc.asp" method="post" onsubmit="return validateform(this)"> <input type="submit" id="submit" value="submit" class="button" onclick="return submitform()"> 

here javascript:

//confirm form submission function submitform() {     if (confirm("are sure want submit form?") == false) {return false}      else {return true} }  //validate form input function validateform(form) {      fail = validdate(form.date.value)     fail += validnum(form.jsia.value)     fail += validnum(form.jsga.value)     fail += validnum(form.yvcia.value)     fail += validnum(form.yvcga.value)      if (fail == "") {return true}     else {alert(fail) return false} }  function validdate(field) {     if (/^\d{2}\/\d{2}\/\d{4}$/.test(field) == false) {return "invalid date format. please enter valid date.\n"}      else {return ""} }  function validnum(field) {     if (isnan(field)) {return "invalid input. please enter valid integer.\n"}      else {return ""} } 

notice i'm using regex validate desired date format. know submitform() function works. pain other 3 functions. please help!

shaun

i fixed it.

//confirm form submission function submitform() {     if (confirm("are sure want submit form?") == false) {return false;}      else {return true;} } //validate attendance form input function validateattendform(form) {      fail = validdate(form.date.value);     fail += validnum(form.jsia.value);     fail += validnum(form.jsga.value);     fail += validnum(form.yvcia.value);     fail += validnum(form.yvcga.value);      if (fail == "") {return true;}     else {alert(fail); return false;} }  function validdate(field) {     re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;     if (re.test(field) == false) {return "invalid date format. please enter valid date.\n";}      else {return "";} }  function validnum(field) {     if (isnan(field) || field != parseint(field)) {return "invalid input. please enter valid interger.\n";}     else {return "";} } 

it issue syntax used validdate() function. pretty plug , play fix.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -