Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 04, 2012 02:20 PM by me_ritz
Member
39 Points
130 Posts
Dec 04, 2012 09:34 AM|LINK
want jquery for validating special characters withour comma and dot (no validation fro these two) in textbox
Contributor
5129 Points
956 Posts
Dec 04, 2012 12:55 PM|LINK
Following function will allow only number and special characteres mentioned in regex now you can modify according yo your need.
add the text in regex which you want to allow in textbox
refer this one
http://babasahebkale.blogspot.in/2012/11/allow-number-and-special-characters-in.html
$(document).ready(function myfunction() {
$("#<%= TextBox1.ClientID %>").keypress(function myfunction(event) {
var regex = new RegExp("^[0-9?=.*!@#$%^&*]+$");
var key = String.fromCharCode(event.charCode ? event.which : event.charCode);
if (!regex.test(key)) {
event.preventDefault();
return false;
}
});
Star
9337 Points
1447 Posts
Dec 04, 2012 02:20 PM|LINK
sridevi.vmb want jquery for validating special characters withour comma and dot (no validation fro these two) in textbox
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $('.keyup-characters').keyup(function () { $('span.error-keyup-2').remove(); var inputVal = $(this).val(); var characterReg = /^\s*[~!@#$%^&*\s]+\s*$/; if (!characterReg.test(inputVal) && inputVal != '') { $(this).after('<span class="error error-keyup-2">Invalid Character.</span>'); } }); }); </script> <asp:TextBox ID="txt" runat="server" CssClass="keyup-characters"></asp:TextBox> <br /> <span class="error-keyup-2"></span>
Sample code...if you still need to allow some more special characters...put that character inside [] (highlighted above)...it will refuse any character that is not inside [].
sridevi.vmb
Member
39 Points
130 Posts
want jquery for validating special characters without comma and dot
Dec 04, 2012 09:34 AM|LINK
want jquery for validating special characters withour comma and dot (no validation fro these two) in textbox
Raigad
Contributor
5129 Points
956 Posts
Re: want jquery for validating special characters without comma and dot
Dec 04, 2012 12:55 PM|LINK
Following function will allow only number and special characteres mentioned in regex now you can modify according yo your need.
add the text in regex which you want to allow in textbox
refer this one
http://babasahebkale.blogspot.in/2012/11/allow-number-and-special-characters-in.html
$(document).ready(function myfunction() {
$("#<%= TextBox1.ClientID %>").keypress(function myfunction(event) {
var regex = new RegExp("^[0-9?=.*!@#$%^&*]+$");
var key = String.fromCharCode(event.charCode ? event.which : event.charCode);
if (!regex.test(key)) {
event.preventDefault();
return false;
}
return false;
});
});
<div><asp:TextBox ID="TextBox1" runat="server" /></div>Mark as Answer, if the post helped you...
Visit My Blog
me_ritz
Star
9337 Points
1447 Posts
Re: want jquery for validating special characters without comma and dot
Dec 04, 2012 02:20 PM|LINK
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $('.keyup-characters').keyup(function () { $('span.error-keyup-2').remove(); var inputVal = $(this).val(); var characterReg = /^\s*[~!@#$%^&*\s]+\s*$/; if (!characterReg.test(inputVal) && inputVal != '') { $(this).after('<span class="error error-keyup-2">Invalid Character.</span>'); } }); }); </script> <asp:TextBox ID="txt" runat="server" CssClass="keyup-characters"></asp:TextBox> <br /> <span class="error-keyup-2"></span>Sample code...if you still need to allow some more special characters...put that character inside [] (highlighted above)...it will refuse any character that is not inside [].