-2

HTML:

<form method="POST" onsubmit="return validateForm()" class="form-inline" >
...
<input type="submit" name="submit" id="submit" value="Add"><br>
<span id="formSuccess"></span>

JavaScript:

function validateAlphabets(fname)
{
  var reg = /^[A-Za-z]+$/;

  if (reg.test(fname.value) == false)
  {
    $("#errorFname").html("Only Alphabets allowed.").css("color", "red");
    return false;
  }
  else
  {
    $("#errorFname").html("Correct").css("color", "green");
    return true;
  }
}

function validateEmail(emailField)
{
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

  if (reg.test(emailField.value) == false)
  {
    $("#errorEmail").html("Enter Valid Email ID.").css("color", "red");
    return false;
  }
  else
  {
    $("#errorEmail").html("Correct").css("color", "green");
    return true;
  }
}

function validateNumber(conum)
{
  if (isNaN(conum.value))
  {
    $("#errorConum").html("Only Numbers allowed.").css("color", "red");
    return false;
  }
  else
  {
    $("#errorConum").html("Correct").css("color", "green");
    return true;
  }
}

function validateForm()
{
  if(validateAlphabets() && validateEmail() && validateNumber())
  {
    $("#formSuccess").html("Form Submitted").css("color", "green");
    return true;
  }
  else
  {
    $("#formSuccess").html("Error").css("color", "red");
    return false;
  }
}

put on hold as off-topic by João Farias, Nitin Rastogi, c32hedge, trashpanda, NarendraC Aug 19 at 5:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development unrelated to testing are off-topic here, but can be asked on Stack Overflow." – João Farias, Nitin Rastogi, c32hedge, trashpanda, NarendraC
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    The questions doesn't seem related to testing - I would suggest posting it at StackOverflow – João Farias Aug 14 at 10:18

Browse other questions tagged or ask your own question.