JS Form Validation [*NOT WORKING*]

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    JS Form Validation [*NOT WORKING*]

    All hardwork going to vein
    PHP Code:
    <?php include "../templates/header.php";?>
    <script type='text/javascript'>
    function formValidator(){// Make quick references to our fields
    var name = document.getElementById('name');
    var subject = document.getElementById('subject');
    var comments = document.getElementById('comments');
    var email = document.getElementById('email');// Check each input in the order that it appears in the form!
    if(isAlphabet(name,"Please enter only letters for your name"))
    {if(isAlphanumeric(subject,"Numbers and Letters Only for Subject"))
    {
    if(isAlphabet(comments,"Please provide a comment!"))
    {
    if(lengthRestriction(name, 3, 8))
    {
    if(emailValidator(email,"Please enter a valid email address"))
    {
    return true;
    }
    }
    }
    }
    }
    return false;
    }
    function notEmpty(elem, helperMsg)
    {
    if(elem.value.length == 0)
    {
    alert(helperMsg);elem.focus(); // set the focus to this input
    return false;
    }
    return true;
    }
    function isNumeric(elem, helperMsg)
    {
    var numericExpression = /^[0-9] $$/;if(elem.value.match(numericExpression))
    {
    return
    true;
    }
    else
    {
    alert(helperMsg);elem.focus();
    return false;
    }
    }
    function isAlphabet(elem, helperMsg)
    {
    var alphaExp = /^[a-zA-Z] $$/;if(elem.value.match(alphaExp))
    {
    return true;
    }
    else
    {
    alert(helperMsg);elem.focus();
    return false;
    }
    }
    function isAlphanumeric(elem,helperMsg)
    {
    var alphaExp = /^[0-9a-zA-Z] $$/;if(elem.value.match(alphaExp))
    {
    return true;
    }
    else
    {
    alert(helperMsg);elem.focus();
    return false;
    }
    }
    function lengthRestriction(elem, min, max)
    {
    var uInput = elem.value;if(uInput.length >= min && uInput.length <= max)
    {
    return true;
    }
    else
    {
    alert("Please enter between" min  " and "  max  " characters!");elem.focus();return false;
    }
    }
    function madeSelection(elem, helperMsg)
    }
    function emailValidator(elem, helperMsg)
    {var emailExp = /^[\w\-\.\ ] \@[a-zA-Z0-9\.\-] \.[a-zA-z0-9]{2,4}$$/;
    if(elem.value.match(emailExp))
    {
    return true;
    }
    else
    {
    alert(helperMsg);elem.focus();
    return false;
    }
    }</script>
    <form action="action.php" method="post" onSubmit="return formValidator">Name<br><input type="text" name="name" id="name"/>
    <br>Email address<br><font color="red">*</font>[<a href="" onClick="vivek()">?</a>]<br><input type="text" name="email" id="email" />
    <br>Subject<br><input type="text" name="subject" id="subject" />
    <br>Your Comments<br>
    <textarea rows="5" name="comments" cols="20" id="comments"></textarea><br>
    <input type="submit" value="Add Comment"/>
    </form><?php include"../templates/footer.php";?>

    #2
    Originally posted by php_n0ob View Post
    All hardwork going to vein
    PHP Code:
    <?php include "../templates/header.php";?>
    <script type='text/javascript'>
    function formValidator(){// Make quick references to our fields
    var name = document.getElementById('name');
    var subject = document.getElementById('subject');
    var comments = document.getElementById('comments');
    var email = document.getElementById('email');// Check each input in the order that it appears in the form!
    if(isAlphabet(name,"Please enter only letters for your name"))
    {if(isAlphanumeric(subject,"Numbers and Letters Only for Subject"))
    {
    if(isAlphabet(comments,"Please provide a comment!"))
    {
    if(lengthRestriction(name, 3, 8))
    {
    if(emailValidator(email,"Please enter a valid email address"))
    {
    return true;
    }
    }
    }
    }
    }
    return false;
    }
    function notEmpty(elem, helperMsg)
    {
    if(elem.value.length == 0)
    {
    alert(helperMsg);elem.focus(); // set the focus to this input
    return false;
    }
    return true;
    }
    function isNumeric(elem, helperMsg)
    {
    var numericExpression = /^[0-9] $$/;if(elem.value.match(numericExpression))
    {
    return
    true;
    }
    else
    {
    alert(helperMsg);elem.focus();
    return false;
    }
    }
    function isAlphabet(elem, helperMsg)
    {
    var alphaExp = /^[a-zA-Z] $$/;if(elem.value.match(alphaExp))
    {
    return true;
    }
    else
    {
    alert(helperMsg);elem.focus();
    return false;
    }
    }
    function isAlphanumeric(elem,helperMsg)
    {
    var alphaExp = /^[0-9a-zA-Z] $$/;if(elem.value.match(alphaExp))
    {
    return true;
    }
    else
    {
    alert(helperMsg);elem.focus();
    return false;
    }
    }
    function lengthRestriction(elem, min, max)
    {
    var uInput = elem.value;if(uInput.length >= min && uInput.length <= max)
    {
    return true;
    }
    else
    {
    alert("Please enter between" min  " and "  max  " characters!");elem.focus();return false;
    }
    }
    function madeSelection(elem, helperMsg)
    }
    function emailValidator(elem, helperMsg)
    {var emailExp = /^[\w\-\.\ ] \@[a-zA-Z0-9\.\-] \.[a-zA-z0-9]{2,4}$$/;
    if(elem.value.match(emailExp))
    {
    return true;
    }
    else
    {
    alert(helperMsg);elem.focus();
    return false;
    }
    }</script>
    <form action="action.php" method="post" onSubmit="return formValidator">Name<br><input type="text" name="name" id="name"/>
    <br>Email address<br><font color="red">*</font>[<a href="" onClick="vivek()">?</a>]<br><input type="text" name="email" id="email" />
    <br>Subject<br><input type="text" name="subject" id="subject" />
    <br>Your Comments<br>
    <textarea rows="5" name="comments" cols="20" id="comments"></textarea><br>
    <input type="submit" value="Add Comment"/>
    </form><?php include"../templates/footer.php";?>

    Check this i had done little bit changes to your script

    <script type='text/javascript'>
    function formValidator(){// Make quick references to our fields
    var name = document.getElementById('name');
    var subject = document.getElementById('subject');
    var comments = document.getElementById('comments');
    var email = document.getElementById('email');// Check each input in the order that it appears in the form!
    if(isAlphabet(name,"Please enter only letters for your name"))
    {
    if(isAlphanumeric(subject,"Numbers and Letters Only for Subject"))
    {
    if(isAlphabet(comments,"Please provide a comment!"))
    {
    if(lengthRestriction(name, 3, 8 ))
    {
    if(emailValidator(email,"Please enter a valid email address"))
    {
    return true;
    }
    }
    }
    }
    }
    return false;
    }
    function notEmpty(elem, helperMsg){
    if(elem.value.length == 0){
    alert(helperMsg);
    elem.focus(); // set the focus to this input
    return false;
    }
    return true;
    }
    function isNumeric(elem, helperMsg)
    {
    var numericExpression = /^[0-9]+$/;
    if(elem.value.match(numericExpression))
    {
    return true;
    }
    else
    {
    alert(helperMsg);
    elem.focus();
    return false;
    }
    }
    function isAlphabet(elem, helperMsg){
    var alphaExp = /^[a-zA-Z]+$/;
    if(elem.value.match(alphaExp)){
    return true;
    }else{
    alert(helperMsg);
    elem.focus();
    return false;
    }
    }
    function isAlphanumeric(elem, helperMsg){
    var alphaExp = /^[0-9a-zA-Z]+$/;
    if(elem.value.match(alphaExp)){
    return true;
    }else{
    alert(helperMsg);
    elem.focus();
    return false;
    }
    }
    function lengthRestriction(elem, min, max){
    var uInput = elem.value;
    if(uInput.length >= min && uInput.length <= max){
    return true;
    }else{
    alert("Please enter between " +min+ " and " +max+ " characters");
    elem.focus();
    return false;
    }
    }
    function madeSelection(elem, helperMsg){
    if(elem.value == "Please Choose"){
    alert(helperMsg);
    elem.focus();
    return false;
    }else{
    return true;
    }
    }
    function emailValidator(elem, helperMsg){
    var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if(elem.value.match(emailExp)){
    return true;
    }else{
    alert(helperMsg);
    elem.focus();
    return false;
    }
    }
    </script>
    <form action="action.php" method="post" onsubmit='return formValidator()'>Name<br><input type="text" name="name" id="name"/>
    <br>Email address<br><font color="red">*</font>[<a href="" onClick="vivek()">?</a>]<br><input type="text" name="email" id="email" />
    <br>Subject<br><input type="text" name="subject" id="subject" />
    <br>Your Comments<br>
    <textarea rows="5" name="comments" cols="20" id="comments"></textarea><br>
    <input type="submit" value="Add Comment"/>
    </form>
    Last edited by anil14353; 25.07.12, 09:20.

    Comment


      #3
      Thanx

      Thanx man...for the help...bt alert for the comment and subject still n0t work...anyway thanx a lot

      Comment


        #4
        Give me the full detail about ur error ?

        Comment


          #5
          Originally posted by $XTREME$ View Post
          Give me the full detail about ur error ?
          here errors means,its n0t working...:D
          it was supposed to show an alert box if comment/subject feild would leave empty,bt its not detecting them

          Comment


            #6
            Originally posted by php_n0ob View Post
            here errors means,its n0t working...:D
            it was supposed to show an alert box if comment/subject feild would leave empty,bt its not detecting them

            <script type='text/javascript'>
            function formValidator(){// Make quick references to our fields
            var name = document.getElementById('name');
            var subject = document.getElementById('subject');
            var comments = document.getElementById('comments');
            var email = document.getElementById('email');// Check each input in the order that it appears in the form!
            if(isAlphabet(name,"Please enter only letters for your name"))
            {
            if(isAlphanumeric(subject,"Numbers and Letters Only for Subject"))
            {
            if(isAlphabet(comments,"Please provide a comment!"))
            {
            if(lengthRestriction(name, 3, )
            {
            if(emailValidator(email,"Please enter a valid email address"))
            {
            return true;
            }
            }
            }
            }
            }
            return false;
            }
            function notEmpty(elem, helperMsg){
            if(elem.value.length == 0){
            alert(helperMsg);
            elem.focus(); // set the focus to this input
            return false;
            }
            return true;
            }
            function isNumeric(elem, helperMsg)
            {
            var numericExpression = /^[0-9]+$/;
            if(elem.value.match(numericExpression))
            {
            return true;
            }
            else
            {
            alert(helperMsg);
            elem.focus();
            return false;
            }
            }
            function isAlphabet(elem, helperMsg){
            var alphaExp = /^[a-zA-Z]+$/;
            if(elem.value.match(alphaExp)){
            return true;
            }else{
            alert(helperMsg);
            elem.focus();
            return false;
            }
            }
            // If the element's string matches the regular expression it is numbers and letters
            function isAlphanumeric(elem, helperMsg){
            var alphaExp = /^[0-9a-zA-Z]+$/;
            if(elem.value.match(alphaExp)){
            return true;
            }else{
            alert(helperMsg);
            elem.focus();
            return false;
            }
            }
            function lengthRestriction(elem, min, max){
            var uInput = elem.value;
            if(uInput.length >= min && uInput.length <= max){
            return true;
            }else{
            alert("Please enter between " +min+ " and " +max+ " characters");
            elem.focus();
            return false;
            }
            }
            function madeSelection(elem, helperMsg){
            if(elem.value == "Please Choose"){
            alert(helperMsg);
            elem.focus();
            return false;
            }else{
            return true;
            }
            }
            function emailValidator(elem, helperMsg){
            var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
            if(elem.value.match(emailExp)){
            return true;
            }else{
            alert(helperMsg);
            elem.focus();
            return false;
            }
            }
            </script>
            <form action="action.php" method="post" onsubmit='return formValidator()'>Name<br><input type="text" name="name" id="name"/>
            <br>Email address<br><font color="red">*</font>[<a href="" onClick="vivek()">?</a>]<br><input type="text" name="email" id="email" />
            <br>Subject<br><input type="text" name="subject" id="subject" />
            <br>Your Comments<br>
            <textarea rows="5" name="comments" cols="20" id="comments"></textarea><br>
            <input type="submit" value="Add Comment"/>
            </form>


            its working...!

            Comment


              #7
              Originally posted by anil14353 View Post
              <script type='text/javascript'>
              function formValidator(){// Make quick references to our fields
              var name = document.getElementById('name');
              var subject = document.getElementById('subject');
              var comments = document.getElementById('comments');
              var email = document.getElementById('email');// Check each input in the order that it appears in the form!
              if(isAlphabet(name,"Please enter only letters for your name"))
              {
              if(isAlphanumeric(subject,"Numbers and Letters Only for Subject"))
              {
              if(isAlphabet(comments,"Please provide a comment!"))
              {
              if(lengthRestriction(name, 3, )
              {
              if(emailValidator(email,"Please enter a valid email address"))
              {
              return true;
              }
              }
              }
              }
              }
              return false;
              }
              function notEmpty(elem, helperMsg){
              if(elem.value.length == 0){
              alert(helperMsg);
              elem.focus(); // set the focus to this input
              return false;
              }
              return true;
              }
              function isNumeric(elem, helperMsg)
              {
              var numericExpression = /^[0-9]+$/;
              if(elem.value.match(numericExpression))
              {
              return true;
              }
              else
              {
              alert(helperMsg);
              elem.focus();
              return false;
              }
              }
              function isAlphabet(elem, helperMsg){
              var alphaExp = /^[a-zA-Z]+$/;
              if(elem.value.match(alphaExp)){
              return true;
              }else{
              alert(helperMsg);
              elem.focus();
              return false;
              }
              }
              // If the element's string matches the regular expression it is numbers and letters
              function isAlphanumeric(elem, helperMsg){
              var alphaExp = /^[0-9a-zA-Z]+$/;
              if(elem.value.match(alphaExp)){
              return true;
              }else{
              alert(helperMsg);
              elem.focus();
              return false;
              }
              }
              function lengthRestriction(elem, min, max){
              var uInput = elem.value;
              if(uInput.length >= min && uInput.length <= max){
              return true;
              }else{
              alert("Please enter between " +min+ " and " +max+ " characters");
              elem.focus();
              return false;
              }
              }
              function madeSelection(elem, helperMsg){
              if(elem.value == "Please Choose"){
              alert(helperMsg);
              elem.focus();
              return false;
              }else{
              return true;
              }
              }
              function emailValidator(elem, helperMsg){
              var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
              if(elem.value.match(emailExp)){
              return true;
              }else{
              alert(helperMsg);
              elem.focus();
              return false;
              }
              }
              </script>
              <form action="action.php" method="post" onsubmit='return formValidator()'>Name<br><input type="text" name="name" id="name"/>
              <br>Email address<br><font color="red">*</font>[<a href="" onClick="vivek()">?</a>]<br><input type="text" name="email" id="email" />
              <br>Subject<br><input type="text" name="subject" id="subject" />
              <br>Your Comments<br>
              <textarea rows="5" name="comments" cols="20" id="comments"></textarea><br>
              <input type="submit" value="Add Comment"/>
              </form>


              its working...!
              thanks a lot for the help buddy...and sorry for the late :D

              Comment

              Working...
              X