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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    validating user input

    hi,

    i have a form which contains some textboxes for name,email,phone,address.the user will enter some values in that.i want to validate them.how to do it.i want to validate the user so that he can enter name in name textbox and number in phone textbox and in email.could you please tell me how to validate this.i want to avoid malicious characters entered by user
    thanks
    mrjameer
    Last edited by mrjameer; 10-24-2006 at 12:52 PM.

  • #2
    Regular Coder
    Join Date
    Oct 2006
    Posts
    181
    Thanks
    1
    Thanked 6 Times in 6 Posts
    does this help

    PHP Code:
    <?php
    if(!$email == "" && (!strstr($email,"@") || !strstr($visitormail,".")))
    {
    echo 
    "<h2>Go Back & Enter A Valid Email Address</h2>";
    }

  • #3
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you should use function "empty()" to check that form fields aren't empty and for checking the phone field you should use "is_numeric()". You can also add a mail verification method (confirming whatever it is by sending a mail which requires to be answered).

    Hope i was usefull


    I also think using validation image is a good addittion (avoid spam). if you are unfamiliar with it you can look at my subscription page in www.thesudokuvalley.com
    Last edited by thebeing; 10-24-2006 at 04:04 PM.

  • #4
    Regular Coder Masterslave's Avatar
    Join Date
    Dec 2005
    Posts
    287
    Thanks
    2
    Thanked 0 Times in 0 Posts
    And use trim();
    When you entered a space, the input field it's not empty anymore but the filled in space is not relevant.

  • #5
    New Coder
    Join Date
    Sep 2006
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use preg_match to check for invalid characters. For example, if you wanted to allow only numbers to be input then you could something like this:

    PHP Code:
    if (preg_match ('[^0-9]',$input))
    {
        die (
    'You can only enter numbers');
    }
    else
    {
        
    // Do whatever you need with the input.



  •  

    Posting Permissions

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