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
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy i am new at js and i need help so bad

    hi guys how you are ?hope u doin good.
    as i said i am new at js and i don't now how to creat a code that control the textbox so it accepts only english alphabits
    i made a code but i didn't work well .
    it just check the first index .
    please help me with this .
    here it is :



    <script language="javascript">
    function checked()
    {
    var str =new String();
    var m;
    var x;
    str=f1.t1.value;
    for(var i=0 ;i<=str.length ;i++)
    {
    m=str.charCodeAt(i);
    if(m>=97 && m<=122)
    x=1;
    else{
    x=0;
    break;
    }
    }
    if (x==1)
    return true;
    else
    alert("the input value is only english");
    return false;

    }
    </script>
    <form name="f1" action="" Onsubmit="return checked()">
    <input type="text" name="t1">
    <input type="submit">

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Umm... I don't really know what I'm talking about, so hopefully someone will be along shortly to explain in simple terms about unicode and character encoding and internationalisation, but... can't you just do a regexp match?

    Code:
    function checked(){
    	return /^[\w\s]+$/.test(document.f1.t1.value);
    }

  • #3
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks alooooooots
    i know it's enough but it is the only way to thank you sir
    i reformed like this
    function checked(){
    [abcdefghijklme...ABCDEF.....].test(f1.t1.value);

    }
    and it worked
    as i told u that i am still new at this and i never seen a code like urs so could u please expalin the followin /^[\w\s]+$/

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    It is a regular expression and you post should have been in the main section since it has nothing to do with frameworks.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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