1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help in textbox

Discussion in 'PHP' started by darkbernz, Feb 21, 2011.

  1. darkbernz

    darkbernz New Member

    Joined:
    Dec 11, 2010
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    none
    Location:
    Philippines
    hello everyone

    i need help in may page. I need a textbox that only accepts alphabets. how it is done?:undecided

    thanks.
     
  2. ManzZup

    ManzZup New Member

    Joined:
    May 9, 2009
    Messages:
    278
    Likes Received:
    43
    Trophy Points:
    0
    Occupation:
    Production Manager:Software @ ZONTEK
    Location:
    Sri Lanka
    Home Page:
    alphabets == alpha_simple_capital??
    you mean without numbers, slashes, commas ?

    if its that you need to make a JS script that runs at the text change so that if the keyCode is not among the 'alphabet' values then its not added to the textbox
    or simply a php script which detect it as an error and show the error message :D
     
    shabbir likes this.
  3. darkbernz

    darkbernz New Member

    Joined:
    Dec 11, 2010
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    none
    Location:
    Philippines
    oh i see.. tnx manzzup.. :nice:
    i will just create a JS.

    hmm.. i wanna know how to use php script to detect numbers and special characters and show the error when these characters was inputed in my textbox..:nice:
     
  4. ManzZup

    ManzZup New Member

    Joined:
    May 9, 2009
    Messages:
    278
    Likes Received:
    43
    Trophy Points:
    0
    Occupation:
    Production Manager:Software @ ZONTEK
    Location:
    Sri Lanka
    Home Page:
    for the php script, you'll be getting the input form POST or GET as usual
    and then run it through a func. just like the JS one

    something like;

    function isAllAlpha($str){
    //your coding
    return true or false
    }

    if(isAllAlpha($_POST['txt'])) echo "OK";
    else echo "Error";
     
    Last edited: Feb 26, 2011
  5. pein87

    pein87 New Member

    Joined:
    Aug 6, 2010
    Messages:
    173
    Likes Received:
    47
    Trophy Points:
    0
    Occupation:
    Web Dev
    Location:
    Limbo
    php has isNumeric() and isNaN() functions you could use to check if its a number. Then create an array with all special characters and loop through it to see if the content contains them or use regex to perform a search for numbers and special characters. Its best if you did this on the client end though since it wont burn server resources doing it.
     
  6. etiergjt

    etiergjt New Member

    Joined:
    Mar 21, 2011
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    I think regex is good to handle this
    Get the input and see if its the type you want with preg_match
     

Share This Page