Results 1 to 4 of 4

Thread: Form Validation

  1. #1
    Join Date
    Jun 2007
    Posts
    72
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Form Validation

    Hey everyone, I know there is loads of stuff about PHP form validation on the net but I just cant get my head around it.
    I am looking for a set of functions that will validate a email field, a purely text field (no numbers or characters), and finally one a field that has text, numbers and characters.

    Am I on the right lines with this:
    PHP Code:
    <?php
    function textandnumbers($field_name_1)
    {
      if(!
    preg_match("/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\]+$/s",$field_name_1)){
        
    $result valid;
     } else {
        
    $result notvalid;}
    }

    function 
    text($field_name_2)
    {
      if(!
    preg_match("/[^a-zA-Z]+$/s",$field_name_2)){
        
    $result valid;
     } else {
        
    $result notvalid;}
    }

    function 
    numbers($field_name_3)
    {
      if(!
    preg_match("/[^0-9]+$/ ",$field_name_3)) {
        
    $result valid;
     } else {
        
    $result notvalid; }
    }
    ?>

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    PHP Code:
    <?php
    function validate($string$type) {
        if(
    $type=="email") {
            
    $valid==eregi('^[0-9a-z]{4,15}[@][0-9a-z]{4,15}[.]([a-z]{2}[.][a-z]{2}|[a-z]{2,4})$'$string)==false?false:true;
        }
        if(
    $type=="text") {
            
    $valid==eregi('^[a-z]+$'$string)==false?false:true;
        }
        if(
    $type=="characters") {
            
    $valid==eregi('^[a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü]+$'$string)==false?false:true;
        }
    ?>
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. #3
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    if you wish to continue to use the
    PERL Compatible Regular Expressions, just move the carat on the other side of the square bracket. By placing it inside the square bracket you are excluding those terms, when you really want it to be only those terms

    Code:
    preg_match("/^[0-9]+$/ ",$field_name_3)

  4. #4
    Join Date
    Jun 2007
    Posts
    72
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default

    Thanks the replys, its much appreciated.

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
  •