form validation

Results 1 to 4 of 4

Thread: form validation

  1. #1
    kate Guest

    Default form validation

    I have a form with following fields <BR>field1<BR>field2<BR>field3<BR>field4<BR><BR>us ers need to fill any of the fields 1,2,3 (required)<BR>if they fill field 3 then field4 is also required<BR>whereas if they fill in field 1 it should be numeric and only accepts either 10 digit or 13 digit numbers any ideas how can I do this validation using js.....I am trying to do it for the past 2 days but it is no working ...please help<BR>thanks

  2. #2
    Steve Cimino Guest

    Default RE: form validation

    Paste what you have so we can troubleshoot it with you... I won&#039;t write it for you, but I&#039;ll help you through it.

  3. #3
    kate Guest

    Default RE: form validation

    tanks here it is I have not figure out how to check the length of digits in first field yet....<BR>function testForms()<BR> { <BR> if <BR> ( lastname()& <BR> document.LocateCust.AcctNum.value.length == " " &<BR> document.LocateCust.PhoneNum.value.length == " " <BR> //(document.LocateCust.LastName.value.length == " " &#124&#124 //document.LocateCust.FirName.value.length == " ") //&#124&#124 <BR> //document.LocateCust.MarketId.selectedIndex == 0 )<BR> <BR> //{ alert ("select a Market ID"); }<BR> ) <BR> //elseif <BR> //var mything = document.LocateCust.AcctNum.value; <BR> //if (mything.length != 10 &#124&#124 mything.length != 13) <BR> // { <BR> //alert("Invalid data."); <BR> // return true; <BR> // } <BR>//}<BR> {<BR> alert("Please enter an Account Number, Home Telephone or Last Name to search Locate Customer.")<BR> return false;<BR> }<BR> else<BR> return true; <BR> } <BR><BR><BR>thanks again

  4. #4
    Steve Cimino Guest

    Default RE: form validation

    &#062;&#062;if (mything.length != 10 &#124&#124 mything.length != 13) <BR><BR>That looks familar... did I give you that before???<BR><BR>Ok, one of your problem is this: &<BR><BR>In JavaScript, & is a bitwise AND, and I&#039;m pretty sure you don&#039;t want that. Use the logical AND (&&) instead. See if that clears things up.<BR><BR>Second thing is you&#039;re checking the length (an integer) to see if it&#039;s a string. Change this:<BR><BR>document.LocateCust.PhoneNum.value.le ngth == " " <BR><BR>to this<BR><BR>document.LocateCust.PhoneNum.value.len gth &#060; 1<BR><BR>This will tell you if it&#039;s a blank or if it&#039;s never been touched.<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