...

View Full Version : i am new at js and i need help so bad



ash.h
04-24-2008, 09:14 AM
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">

Spudhead
04-24-2008, 11:34 AM
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?


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

ash.h
04-26-2008, 08:56 AM
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]+$/

A1ien51
04-27-2008, 09:45 PM
It is a regular expression and you post should have been in the main section since it has nothing to do with frameworks.

Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum