BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/)
-   How to ? (http://bzupages.com/307-how/)
-   -   How to Allow text box only for alphabets using Jquery (http://bzupages.com/f307/how-allow-text-box-only-alphabets-using-jquery-17042/)

.BZU. 23-07-2011 07:07 AM

How to Allow text box only for alphabets using Jquery
 
If you want to make the text box allow only alphabets (a-z) using Jquery. it is easy to do so...

HTML Code:

<input name="Texting" onkeyup="this.value=this.value.replace(/[^a-z]/g,'');">
OR for Smaller and Upper both cases


HTML Code:

<input name="First Name" type="text" id="fn" class="textbox" onkeyup="this.value=this.value.replace(/[^a-z,A-Z,.]/g,'');"/>
And can be the same to onblur for evil user who like to paste instead of typing ;)

HTML Code:

<input name="lorem" class="alphaonly">
<script type="text/javascript">
$('.alphaonly').bind('keyup blur',function(){
    $(this).val( $(this).val().replace(/[^a-z]/g,'') ); }
);
</script>

You shouldn't use HTML attributes to attach events, especially when something as easy as jQuery is available to properly attach the event handler.


All times are GMT +5. The time now is 01:11 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.