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 4 of 4

Thread: inout filter

  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    inout filter

    Hello all
    I use a script which is in smarty , the inputs only validates by javascript.
    I wanna use a php script to filter some fields , to pass only digits or alphabet.

    can you help me ? to use any script BESIDE the main script to control inputs before get POST ?

    (Im not a php developer , )

    Thanks all

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    159
    Thanks
    2
    Thanked 15 Times in 15 Posts
    You cannot control what a user type in a text field before it is sent to the server (as PHP is Server-Side) i.e. before the data is posted. Once posted however you can check what has been inputted and show an error message if it isn't alphanumerical. Javascript is Client-Side so would be able to filter text-inputs


    The PHP for checking for numbers or alphabet characters only is:

    PHP Code:
    if (ereg('[A-Za-z0-9]',$_POST['inputfield'])){
    echo 
    "VALID!";
    } else {
    echo 
    "INVALID!";


  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JordanW View Post
    You cannot control what a user type in a text field before it is sent to the server (as PHP is Server-Side) i.e. before the data is posted. Once posted however you can check what has been inputted and show an error message if it isn't alphanumerical. Javascript is Client-Side so would be able to filter text-inputs


    The PHP for checking for numbers or alphabet characters only is:

    PHP Code:
    if (ereg('[A-Za-z0-9]',$_POST['inputfield'])){
    echo 
    "VALID!";
    } else {
    echo 
    "INVALID!";

    Thanks, but
    I wanna 1 filed to accept digits ONLY , I tried ereg('[0-9]') but if we combine alphabet and digit it cant stop the post for example :

    test ===> returns INVALID but test123 ===>returns VALID
    I need it only to accept nombers,

    Also I need another input to accept ONLY alphabet , no digit..

    I tested also preg_match("/[^0-9]+$/ ") but the same problem, accepts combination of nomber and alphabet.

    Thanks

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JordanW View Post
    You cannot control what a user type in a text field before it is sent to the server (as PHP is Server-Side) i.e. before the data is posted. Once posted however you can check what has been inputted and show an error message if it isn't alphanumerical. Javascript is Client-Side so would be able to filter text-inputs


    The PHP for checking for numbers or alphabet characters only is:

    PHP Code:
    if (ereg('[A-Za-z0-9]',$_POST['inputfield'])){
    echo 
    "VALID!";
    } else {
    echo 
    "INVALID!";

    It was ok, I made mistake, thanks Jordan


  •  

    Posting Permissions

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