Results 1 to 3 of 3

Thread: Need to validate form by PHP.

  1. #1
    Join Date
    Jan 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need to validate form by PHP.

    I have made a form which have two input field.
    Now I need to validate those input.
    Here is the Form
    HTML Code:
    <form name="form1" action="form2.php" method="post">
    <input type="text" value="" name="credit" size="11" maxlength="11"/>
    <input type="text" value="" name="credit2" size="11" maxlength="11"/>
    <input type="submit" value="submit" />
    </form>
    Now I need to validate them.
    As I am only 16 and completely new in PHP, I am unable to validate them.
    Please give me some codes which can validate those field.
    I need to set the values of those fields as-


    1. Values must be digits(0123456789).
    2. Maximum and minimum length is 11.
    3. 2 Values must be same.
    4. First 3 digit must be 017 or 018 or 019 or 011.
    5. If first 3 digit is 017 then $provider = "GrameenPhone";
    6. If first 3 digit is 018 then $provider = "Aktel";
    7. If first 3 digit is 019 then $provider = "Banglalink";
    8. If first 3 digit is 011 then $provider = "Citycell";

    Please do them with php.
    Make it by -
    if ($_POST['credit'] != $_POST['credit2']) {
    echo "Valuse are not same";
    }
    elseif (Please help me to code here to validate values as disired.) {
    }
    else {
    I will handle this section.
    }
    Please help me by doing this.
    Last edited by shakti; 01-08-2009 at 03:45 PM.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    PHP Code:
    <?php
      $digits 
    "234234929";
      switch (
    substr($digits03)) {
          case 
    '123':
              
    $provider "Hello";
              break;
          case 
    '234':
              
    $provider "Hey";
              break;
          default:
              
    $provider "Hi";
      }
      echo 
    $provider;
    ?>
    Jeremy | jfein.net

  3. #3
    Join Date
    Nov 2008
    Posts
    58
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Default

    Checkout the PHP form validation script here:
    PHP form validation

    Also, it is a good idea to do the validations at the client side as well, using JavaScript(the response is immediate)
    checkout this JavaScript form validation script.

Bookmarks

Posting Permissions

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