|
-
Jul 31st, 2011, 06:04 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] ascii code [javascript]
hi,
I want to know how to get ascii code for a letter, can anyone will tell me?
i searched a lot but couldn't find the javaScript functions..
thanks..
-
Jul 31st, 2011, 06:29 AM
#2
Re: ascii code [javascript]
Check this: http://jalaj.net/2007/03/08/asc-and-chr-in-javascript/
Example:
html Code:
<html>
<body>
<script type="text/javascript">
var txt = "A";
document.write(txt.charCodeAt(0));
</script>
</body>
</html>
It will return 65
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jul 31st, 2011, 06:43 AM
#3
Thread Starter
Hyperactive Member
Re: ascii code [javascript]
 Originally Posted by akhileshbc
thanks 
i had seen that web page before.
i'm reading character by character and want to check. Can u tell me where i'm wrong?
Code:
<html>
<head>
<title>verify</title>
<script>
function check()
{
var str=document.my.first.value;
for(i=0; i<=str.length; i++)
{
if((str.charCodeAt(i)>=48 && str.charCodeAt(i)<=57) || (str.charCodeAt(i)>=97 && str.charCodeAt(i)<=122))
{
alert("valid");
break;
}
else
{
alert("Invalid");
break;
}
}
}
</script>
</head>
<body>
<form name=my id="my">
<table>
<tr>
<td><input type='text' name='first'></td><td></td>
</tr>
<tr>
<td><input type='button' name='click' value='check ' onClick='check()'></td>
</tr>
</table>
</body>
</html>
-
Jul 31st, 2011, 06:46 AM
#4
Re: ascii code [javascript]
Use
Because the array starts from 0. So the upperbound would be 1 less than the length.
If you still get any problems, let me know the input value you have given.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jul 31st, 2011, 06:51 AM
#5
Thread Starter
Hyperactive Member
Re: ascii code [javascript]
no, it says valid for , . e.t.c
i want to limit my characters from a to z and from 0 to 9.
-
Jul 31st, 2011, 06:52 AM
#6
Re: ascii code [javascript]
Code:
<html>
<head>
<title>verify</title>
<script>
function check()
{
var str=document.my.first.value;
var f=0;
for(i=0; i<=str.length-1; i++)
{
if((str.charCodeAt(i)>=48 && str.charCodeAt(i)<=57) || (str.charCodeAt(i)>=97 && str.charCodeAt(i)<=122))
{
f=0;
}
else
{
f=1;
break;
}
}
if(f==1)
alert("Invalid");
else
alert("Valid");
}
</script>
</head>
<body>
<form name=my id="my">
<table>
<tr>
<td><input type='text' name='first'></td><td></td>
</tr>
<tr>
<td><input type='button' name='click' value='check ' onClick='check()'></td>
</tr>
</table>
</body>
</html>
Also, you have to change statements in TRUE part of IF condition. What you have done is, you'll start checking each character. If it is valid, you will display a message and breaks the execution of the FOR loop. But that will prevent the code from checking other characters !
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jul 31st, 2011, 07:07 AM
#7
Thread Starter
Hyperactive Member
Re: ascii code [javascript]
yeah, u're right. I did it.
Code:
function check()
{
var str=document.my.first.value;
for(i=0; i<=str.length-1; i++)
{
if((str.charCodeAt(i)>=48 && str.charCodeAt(i)<=57) || (str.charCodeAt(i)>=97 && str.charCodeAt(i)<=122))
{
}
else
{
alert("Invalid");
break;
}
}
}
my stupid mistake
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|