Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Min Length for Text Area Help

    Hi guys, I am trying to have my text area part of my form have a minimum character length of 3 and a max of 150. Not sure how to do this since html 5 only allows max length. I think Jquery might be the best bet but not 100% sure. This is the jquery I tried but it did not work.
    Code:
    <head>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script>
    <script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>
    <script>
    </head>
    <body>
    jQuery.validator.setDefaults({
      debug: true,
      success: "valid"
    });
    $( "#message" ).validate({
      rules: {
        field: {
          required: true,
          minlength: 3
        }
      }
    });
    </script>
    Here is my html code
    Code:
    <!DOCTYPE HTML>
    <html> 
    <head>
    <link type="text/css" rel="stylesheet" href="index.css" />
    <meta name="viewport" content="width=device-width" />
    <title>Daily Dorm News</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    <script>
    $(function() {
    $( "#datepicker" ).datepicker();
    });
    </script>
    <body>
    
    
    
    <form id="myform"> <u>Daily Dorm News</u> <br> The best place to get your latest Dorm news </form>
    <form action="posting_wall.php" method="get">
    <div id="container">
    Username:<input type="text" name="name" pattern="[A-Za-z0-9]{3,15}" title="Letters and numbers only, length 3 to 15" required autofocus><br>
    E-mail: <input type="email" name="email"maxlength="20" required><br>
    <div class='message'>
    Post: <br>
    <textarea rows="10" cols="50" name='message' id='message'></textarea>
    </div>
    Date this event took place: <input type="text" name='date' id="datepicker" required> <br>
    </div>
    <input type="submit">
    <input type="reset" value="Reset">
    </form>
    
    </body>
    </html>
    Here is my php code
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta name="viewport" content="width=device-width" />
    <title>Daily Dorm News</title>
    </script>
    <body>
    </head>
    <body>
    <h1>Your Daily Dorm News Post! </h1>
    
    Welcome <?php if ( isset($_GET['name']) and preg_match("/^[A-Za-z0-9]+$/", $_GET['name']) ) {
    
        echo $_GET['name'];
    
    } else {
    
        echo "You entered an invalid name!\n";
    
    }
    
    ?><br>
    
    
    Your email address is: <?php if ( isset($_GET['email']) and preg_match("/.+@.+\..+/i", $_GET['email']) ) {
    
        echo $_GET['email'];
    
    } else {
    
        echo "You didn't enter a proper email address!\n";
    
    }
    ?><br>
    You Posted : <?php echo $_GET["message"]; ?><br>
    
    
    This event happened :<?php echo $_GET["date"]; ?><br>
    
    <?php
    // set the default timezone to use. Available since PHP 5.1
    date_default_timezone_set('EST');
    
    
    // Prints something like: Monday 8th of August 2005 03:12:46 PM
    echo date('l jS \of F Y h:i:s A');
    ?>
    </script>
    </body>
    </html>

  • #2
    New to the CF scene
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try This:

    Code:
    <?php 
    $name="";
    if(isset($_GET['name']) and preg_match("/^[A-Za-z0-9]+$/", $_GET['name']) ) {
    
    	if (strlen($name) < 3);
    	{
    	echo "name to short!";
    	die();
    	}
    	else if {strlen($name) > 10);
    	{
    	echo "name to long!";
    	die();
    	}
    	else
    	{
        echo $_GET['name'];
    	}
    }
    
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •