saravanataee Posted February 19, 2013 Share Posted February 19, 2013 Dear all, I have having a text area field which has a limit of 100 characters only. Now, i also want to validate it such that it should only contain letter's (alphabet A-Z .a-z). It should not contain any number or @ symbol. If such things entered it should throw me an error saying invalid arguments like that. I know it can be done with regular expressions. But i m not aware of how to do. Can some one help with that. Here is my script. <script language="javascript" type="text/javascript"> function limitText(limitField, limitCount, limitNum) { if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum); } else { limitCount.value = limitNum - limitField.value.length; } } </script> <tr> <td valign="top" align="left">Description</td> <td valign="top">:</td> <td align="left"><textarea name="limitedtextarea" onkeydown="limitText(this.form.limitedtextarea,this.form.countdown,100);" onkeyup="limitText(this.form.limitedtextarea,this.form.countdown,100);"> </textarea><br> <font size="1">(Maximum characters: 100)<br> You have <input readonly type="text" name="countdown" size="3" value="100"> characters left.</font></td> </tr> Link to comment https://forums.phpfreaks.com/topic/274662-validation-on-textarea-to-allow-only-characters-no-numbers/ Share on other sites More sharing options...
requinix Posted February 19, 2013 Share Posted February 19, 2013 Take a quick look at documentation for regular expressions in Javascript. The MDN is a good place to check for examples. Once you know about the .test() method you can use /^[a-zA-Z]{0,100}$/ That will also validate the length. Link to comment https://forums.phpfreaks.com/topic/274662-validation-on-textarea-to-allow-only-characters-no-numbers/#findComment-1413277 Share on other sites More sharing options...
saravanataee Posted February 20, 2013 Author Share Posted February 20, 2013 Hi requinix, Thanks for the reply. But i want to know the way i can apply the method into my textarea. Since i m not that expert, i want your help in that. Just show me the javascript function which can be called to test it.. Thanks! Link to comment https://forums.phpfreaks.com/topic/274662-validation-on-textarea-to-allow-only-characters-no-numbers/#findComment-1413588 Share on other sites More sharing options...
requinix Posted February 20, 2013 Share Posted February 20, 2013 I told you where to look, hoping that you didn't need a link to click on. Have you been able to find anything? The point is to get you to learn a bit so you don't have to rely on others. Link to comment https://forums.phpfreaks.com/topic/274662-validation-on-textarea-to-allow-only-characters-no-numbers/#findComment-1413605 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.