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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Location
    Pakistan
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts

    character type check

    hi i have a form with fields like name, address
    i want a server side check to control that the user could not enter integer values in Name Field
    e.g. if he/she enter name like aamir1, 1aamir, aa1mir,
    then message should appear, only character values acceptable.
    God helps those who help others.

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code:
    <?php
    function checkstring($chkstr) {
       $numin = FALSE;
       for ($i = 0; $i < strlen($chkstr); $i++) {
          if is_int($chkstr[$i]) {
             $numin = TRUE;
          }
       }
       return $numin;
    }
    
    if (checkstring($_POST['name'])) {
       echo 'Your name cannot contain numbers';
    }
    ?>

    ~Phil~

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Location
    Pakistan
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanx
    but does not work
    God helps those who help others.

  • #4
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Blah. Don't say it doesn't work! You have to explain what doesn't work.

    ~Phil~

  • #5
    Regular Coder
    Join Date
    Mar 2005
    Location
    Pakistan
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i have tried that but may b i m unable to use that plz try it and send me the exact code
    God helps those who help others.

  • #6
    Regular Coder
    Join Date
    Mar 2005
    Location
    Pakistan
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    now it works

    function checkstring($chkstr) {
    $numin = FALSE;
    for ($i = 0; $i < strlen($chkstr); $i++) {
    if (is_numeric($chkstr[$i])) {
    $numin = TRUE;
    }
    }
    return $numin;
    }
    God helps those who help others.

  • #7
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    huh? That is the exact code I gave you

  • #8
    Regular Coder
    Join Date
    Mar 2005
    Location
    Pakistan
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    u were using is_int and it does not work with that.
    God helps those who help others.


  •  

    Posting Permissions

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