can anybody tel methat how to resctrict the user to enter only alphabets in a form field.
if it is not possible in php then tell me javascript code
Can anybody tell me about ....
Moderator: General Moderators
- technofreak
- Forum Commoner
- Posts: 74
- Joined: Thu Jun 01, 2006 12:30 am
- Location: Chennai, India
- Contact:
Buddy,
You have to decide between PHP and Javascript. PHP does the processing on the server side, while JS does on the client side. This means, when a user types non-alphabetic charecters, PHP will find it only when they submit the whole set of data and it will be rejected by the PHP(in the server). Actually, this is a performance overhead. If you use JS, then you can detect the same as the user types the content and show up a warning to the user at the same instant. Thus, the load on the server/PHP to validate your form on the its end reduces, thereby improving the performance.
If you want to learn how do it in PHP, a simple reg-ex to find non alphabetical charecters can do the job. I am not aware of Javascripts, Please refer to a online tutorial which can teach you how to write simple javascripts like this. Search the mighty web for more details on reg-ex and javascripts.
HTH !
You have to decide between PHP and Javascript. PHP does the processing on the server side, while JS does on the client side. This means, when a user types non-alphabetic charecters, PHP will find it only when they submit the whole set of data and it will be rejected by the PHP(in the server). Actually, this is a performance overhead. If you use JS, then you can detect the same as the user types the content and show up a warning to the user at the same instant. Thus, the load on the server/PHP to validate your form on the its end reduces, thereby improving the performance.
If you want to learn how do it in PHP, a simple reg-ex to find non alphabetical charecters can do the job. I am not aware of Javascripts, Please refer to a online tutorial which can teach you how to write simple javascripts like this. Search the mighty web for more details on reg-ex and javascripts.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Yes, it is very possible and very easy. But you seriously need to a little work on your own before someone here does anything for you. Seach google or even these forums for 'alpha regex'. Then look up regular expression matching or something to that effect for code samples. After you try some things, if you still need help, post back and someone, I'm sure, will help you.
Actually, you shouldn't decide between JS and PHP, you should use both. Validating on the client side is always a good idea as technofreak mentioned, but you need to do the same on the server side (the receiving PHP script) because the user may have JS turned off, for whatever reason. Or a malicious user may circumvent any client side checks you have. Heck, most form submissions on most sites can be completely faked and altered.
You can perform the same task using the same regular expression in both JS and PHP.
You can perform the same task using the same regular expression in both JS and PHP.
-
rameshmrgn
- Forum Newbie
- Posts: 15
- Joined: Sat Jun 17, 2006 1:01 am
Pimptastic | Please use
Pimptastic | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
Try This....Code: Select all
<html >
<head>
<script language="javascript" type="text/javascript">
function checkMe(txtBox)
{
if(!((event.keyCode >= 65 && event.keyCode<=90) || (event.keyCode >= 97 && event.keyCode<=122)))
{
event.keyCode=0;
}
}
</script>
</head>
<body>
<input type="text" name="alpha" onkeypress="checkMe(this)" />
</body>
</html>Pimptastic | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]That's all find and well, but would you mind explaining exactly what that does to eshban?rameshmrgn wrote: Hi,
Try This....Code: Select all
<html > <head> <script language="javascript" type="text/javascript"> function checkMe(txtBox) { if(!((event.keyCode >= 65 && event.keyCode<=90) || (event.keyCode >= 97 && event.keyCode<=122))) { event.keyCode=0; } } </script> </head> <body> <input type="text" name="alpha" onkeypress="checkMe(this)" /> </body> </html>
Note:
Everah wrote: Yes, it is very possible and very easy. But you seriously need to a little work on your own before someone here does anything for you. Seach google or even these forums for 'alpha regex'. Then look up regular expression matching or something to that effect for code samples. After you try some things, if you still need help, post back and someone, I'm sure, will help you.