Jump to content

driving me crazy


choobakka

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)

Link to comment
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??

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...