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
    Nov 2006
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Question - prevent people entering numbers?

    can i prevent users from entering numbers into my HTML form.
    and the opposite a code to stop people entering letter into some firelds

    does anyone know the code that detects false names

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Not sure if this is right, but I'm taking a shot at it:

    To keep numbers out
    PHP Code:
    $letters_only $_POST['letters_only'];

    if (!
    ereg("([A-Za-z])"$letters_only)) {
    //Error code here

    To keep letters out:
    PHP Code:
    $numbers_only $_POST['numbers_only'];

    if (!
    ereg("([0-9])"$numbers_only)) {
    //Error code here

    I'm not sure what you mean about 'detecting false names'...

    What is a false name?

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    Regular Coder
    Join Date
    Nov 2006
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well it bascically contains what you put above so numbers wouldn'yt be in a name but these might ' - understand what i mean.

    whrere would i put the above code.

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Well it bascically contains what you put above so numbers wouldn'yt be in a name but these might ' - understand what i mean.
    In other words, a 'name' could contain letters or symbols but not numbers?

    Assuming that is what you mean, the code might be something like this:

    name validation
    PHP Code:
    $name $_POST['name'];

    if (!
    ereg("([0-9ANY_SYMBOLS_HERE])"$name)) {
    //Error code here

    whrere would i put the above code.
    In your form handler (eg the file that receives the POST variables from your form and validates them and puts them in a database or emails them to you or whatever).

    HTH,
    Dan
    Last edited by whizard; 12-23-2006 at 08:39 PM.
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #5
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    All Regex aside, if your patterns aren't to complicated you may want to check out the ctype functions:
    http://us2.php.net/ctype


    good luck.


  •  

    Posting Permissions

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