Jump to content
Sign in to follow this  
choobakka

driving me crazy

Recommended Posts

here is a sample of my code:var returnValue = true;var firstname = frmShuffle.firstName.value;var lastname = frmShuffle.lastName.value;if (firstname != "") { //if entry is not empty returnValue = true; if (firstname.match(/\d/) != null) { //if entry is a number returnValue = false; alert("you have entered a number"); }} else { // empty so skip all of abovereturnValue = false;alert("Please enter your First Name");return returnValue;}if (lastname.length == 0) {returnValue = false;alert("Please enter your Second Name");frmShuffle.lastName.focus();return returnValue;}the problem i am having is with the code in italic. what i want to happen is that the browser checks if the field is empty. if it is not then true is returned but then another IF statement is executed to check its content (ie for numbers). if numbers are found then false is returned. the problem is that if text is entered eveything is fine. however, when a number is entered, the validation takes place BUT once the validation has taken place, it executes the next statement (in bold). however, i would like it keep re-checking for numbers and THEN once the validation is satisfied ie text with no numbers, only then should it move on to the next statement (in bold)

Share this post


Link to post
Share on other sites
here is a sample of my code:the problem is that if text is entered eveything is fine. however, when a number is entered, the validation takes place BUT once the validation has taken place, it executes the next statement (in bold). however, i would like it keep re-checking for numbers and THEN once the validation is satisfied ie text with no numbers, only then should it move on to the next statement (in bold)

if (firstname != "") {   if (firstname.match(/\d/) != null)   {       alert("you have entered a number");       return false;   }}else {    alert("Please enter your First Name");   return false;}if (lastname.length == 0) {  alert("Please enter your Second Name");  frmShuffle.lastName.focus();  return false;}

Is this the solution??

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...