javascript ..very urgent

Results 1 to 3 of 3

Thread: javascript ..very urgent

  1. #1
    reid Guest

    Default javascript ..very urgent

    Friends<BR>Please help me in doing this validation.<BR>I have 2 functions in Javascript one for date validations and one to check the number entered is valid,i am new to this Javascript also i have 3 more form fields to validate.I copied these scripts from internet resources,but the thing is at both the places they are calling the script from forms onsubmit event handler,i dont know how to do this, can anybody help me.<BR>thanx

  2. #2
    Join Date
    Dec 1969

    Default RE: javascript ..very urgent

    Include the code in your text and maybe we can give you some pointers!

  3. #3
    reid Guest

    Default RE: javascript ..very urgent

    this is my date validation code and i am clling it from form&#039s onsubmit event handler.<BR><BR>function isValidDate(dateStr) {<BR>// Checks for the following valid date formats:<BR>// MM/DD/YY MM/DD/YYYY MM-DD-YY MM-DD-YYYY<BR>// Also separates date into month, day, and year variables<BR><BR>var datePat = /^(d{1,2})(/&#124-)(d{1,2})2(d{2}&#124d{4})$/;<BR><BR>// To require a 4 digit year entry, use this line instead:<BR>// var datePat = /^(d{1,2})(/&#124-)(d{1,2})2(d{4})$/;<BR><BR>var matchArray = dateStr.match(datePat); // is the format ok?<BR>if (matchArray == null) {<BR>alert("Date is not in a valid format.")<BR>return false;<BR>}<BR>month = matchArray[1]; // parse date into variables<BR>day = matchArray[3];<BR>year = matchArray[4];<BR>if (month &#060; 1 &#124&#124 month &#062; 12) { // check month range<BR>alert("Month must be between 1 and 12.");<BR>return false;<BR>}<BR>if (day &#060; 1 &#124&#124 day &#062; 31) {<BR>alert("Day must be between 1 and 31.");<BR>return false;<BR>}<BR>if ((month==4 &#124&#124 month==6 &#124&#124 month==9 &#124&#124 month==11) && day==31) {<BR>alert("Month "+month+" doesn&#039t have 31 days!")<BR>return false<BR>}<BR>if (month == 2) { // check for february 29th<BR>var isleap = (year % 4 == 0 && (year % 100 != 0 &#124&#124 year % 400 == 0));<BR>if (day&#062;29 &#124&#124 (day==29 && !isleap)) {<BR>alert("February " + year + " doesn&#039t have " + day + " days!");<BR>return false;<BR> }<BR>}<BR>return true; // date is valid<BR><BR>and this is to check for valid zip.<BR><BR><BR>function isNum(passedval){<BR> if(passedval==""){<BR> return false<BR> }<BR> for (i=0;i&#060;passedval.length;i++){<BR> if (passedval.charAt(i)&#060;"0"){<BR> return false<BR> }<BR> if (passedval.charAt(i)&#062;"9"){<BR> return false<BR> }<BR> }<BR> return true<BR> }<BR>function validzip(inzip){<BR> if (inzip ==""){<BR> return true<BR> }<BR> if (isNum(inzip)){<BR> return true<BR> }<BR> return false<BR>}<BR>}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts