form validation using php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sudhakar

    form validation using php

    hi

    i need to validate a field in a form where a user enters their
    lodgement number as part of a registration form. this lodgement number
    can have letters, numbers, spaces and special characters. i do not
    know exactly what those special characters are, so do i have to define
    the type of special characters and validate accordingly.

    presently my php code for validating the lodgement number is

    $lodgementtf = $_POST["lodgementt f"];

    if($lodgementtf == "" || !preg_match("/^[a-zA-Z0-9_ <]+$/",
    $lodgementtf) )
    {
    echo "display error message":
    }


    i also have another way of validating

    if($lodgementnu mber == "" || !preg_match("/^[a-zA-Z0-9_ !-@£$%^&*()]+
    $/", $lodgementnumbe r) )

    does this mean that the special characters can only be = a space AND
    _!-@£$%^&*() and no other special characters.

    please advice.

    thanks.
  • Mitch Sherman

    #2
    Re: form validation using php

    On Tue, 13 May 2008 23:18:37 -0700 (PDT), Sudhakar
    <sudhakararaog@ gmail.comwrote:
    >i also have another way of validating
    >
    >if($lodgementn umber == "" || !preg_match("/^[a-zA-Z0-9_ !-@£$%^&*()]+
    >$/", $lodgementnumbe r) )
    >
    >does this mean that the special characters can only be = a space AND
    >_!-@£$%^&*() and no other special characters.
    You will want to escape out that carat (\^) to match the carat symbol
    (^).

    Mitch

    Comment

    • Mitch Sherman

      #3
      Re: form validation using php

      On Tue, 13 May 2008 23:18:37 -0700 (PDT), Sudhakar
      <sudhakararaog@ gmail.comwrote:
      >i also have another way of validating
      >
      >if($lodgementn umber == "" || !preg_match("/^[a-zA-Z0-9_ !-@£$%^&*()]+
      >$/", $lodgementnumbe r) )
      >
      >does this mean that the special characters can only be = a space AND
      >_!-@£$%^&*() and no other special characters.
      You can also escape the dash and the carat ("\\-\\^").

      Mitch

      Comment

      Working...