How to allow only english to be entered into textbox

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to allow only english to be entered into textbox

    hi wapmasters ,
    can anybody tell me how can i allow only english test to be entered into a text box
    or, if a text is entered in any other language how can i replace it with a blank space or empty string ?

    thanx

    #2
    u need an english dictionary to test all possible values

    Comment


      #3
      no no .. i don't want to test it is a valid english word or not. i just want to test whether the string contains only "a-z,A-Z and other symbols" means it should not be using arabic,chinese or other such characters . What i want to block is something like this مقاطع سكس

      thanx

      Comment


        #4
        ok thats what you ment

        use regular expressions
        PHP Code:
        $word = isset($_POST['word']) ? trim($_POST['word']) : '';

        if(!
        preg_match("#^([a-zA-Z0-9_-+]+)$#"$word$m))
        {
           echo 
        "invalid characters supplied";
        }
        else
        {
           
        print_r($m); //matches that were found

        Comment


          #5
          thanx bro for the help

          Comment


            #6
            Your welcome a better way to do this though to prevent mix characters

            PHP Code:

            $error 
            0;

            $word  = isset($_POST['word']) trim($_POST['word']) : '';

            for(
            $i=0$i<=strlen($word); $i++)
              {
                 if(!
            preg_match("/([a-zA-Z0-9_-+])/"$word[$i], $m))
                 {
                   break;
                   
            $error 1;
                 }
                  
              } 

            if(
            $error==1)
            {
              echo 
            "incorrect word only aphanumeric chars";
            }
            else
            {
              echo 
            "you have passed the test";
            }
            //end 

            Comment


              #7
              Originally posted by antony2kx View Post
              Your welcome a better way to do this though to prevent mix characters

              PHP Code:

              $error 
              0;

              $word  = isset($_POST['word']) trim($_POST['word']) : '';

              for(
              $i=0$i<=strlen($word); $i++)
                {
                   if(!
              preg_match("/([a-zA-Z0-9_-+])/"$word[$i], $m))
                   {
                     break;
                     
              $error 1;
                   }
                    
                } 

              if(
              $error==1)
              {
                echo 
              "incorrect word only aphanumeric chars";
              }
              else
              {
                echo 
              "you have passed the test";
              }
              //end 
              So if someone types a word in Serbian "zdravo" which means "hello" in English will pass the filter. Also, if someone writes "hello, how are you?" will not pass the filter. o.O

              Try this:

              PHP Code:
              $pspell_link pspell_new("en");
              $word explode(" "$message);
              foreach(
              $word as $k => $v) {
                 if (
              pspell_check($pspell_link$v)) {
                    echo 
              "spelled right";
                 } else {
                    echo 
              "Sorry, wrong spelling";
                 };
              }; 
              Last edited by arnage; 17.06.11, 16:42.
              <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

              Comment


                #8
                If you look clearly at what help was wanted you would have seen that the code i have written is exactly what was asked for, if he wanted english statements then i could have inlcuded commas etc, but what was was asked for is that the text box should only accept a-zA-z0-9, juts look keenly before you reply.

                even though zdravo is sebian its still alpha chars so it would pass,

                what this code really works good on is that it helps to prevent other special chars, like russian etc.

                Comment


                  #9
                  Originally posted by antony2kx View Post
                  If you look clearly at what help was wanted you would have seen that the code i have written is exactly what was asked for, if he wanted english statements then i could have inlcuded commas etc, but what was was asked for is that the text box should only accept a-zA-z0-9, juts look keenly before you reply.

                  even though zdravo is sebian its still alpha chars so it would pass,

                  what this code really works good on is that it helps to prevent other special chars, like russian etc.
                  Me? Do u understand english well? Here is what he asked:

                  "hi wapmasters ,
                  can anybody tell me how can i allow only english test to be entered into a text box
                  or, if a text is entered in any other language how can i replace it with a blank space or empty string ?

                  thanx"

                  He did not asked for that what u have posted. Period.
                  <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

                  Comment


                    #10
                    PHP Code:
                    function validChar($string){
                    $string preg_replace("/[^A-Za-z0-9.,!@#$%^&*()-=_+]/","",$string);
                    return 
                    $string;

                    Did I help you?
                    You can help me too
                    Your donations will help me finance my studies.

                    Comment


                      #11
                      dude the guy ment a-z 0-9 only so just relax, cant you see he said thanks that it worked for him, why are you cursing, dont brag, if i never knew english i owuld not be doing my masters now in computer engineering science and i am just 20; lol

                      Comment


                        #12
                        Originally posted by antony2kx View Post
                        dude the guy ment a-z 0-9 only so just relax, cant you see he said thanks that it worked for him, why are you cursing, dont brag, if i never knew english i owuld not be doing my masters now in computer engineering science and i am just 20; lol
                        This is what he ment with "only in english":
                        PHP Code:
                        $pspell_link pspell_new("en"); 
                        $word explode(" "$message); 
                        foreach(
                        $word as $k => $v) { 
                           if (
                        pspell_check($pspell_link$v)) { 
                              echo 
                        "spelled right"
                           } else { 
                              echo 
                        "Sorry, wrong spelling"
                           }; 
                        }; 
                        You, please, leave me alone, don't explain anything more. I do not want to discuss with you on this issue, but it seems that you just want to argue.
                        Cheers.
                        <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

                        Comment


                          #13
                          all the wapmasters, thanx for your help. . What i needed was a basic idea on how to do it , i can easily mod it out. By the way @arnage that snippet was very helpful and i am gonna implement that.. Thanx

                          Comment


                            #14
                            U r welcome bro.
                            <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

                            Comment

                            Working...
                            X