function validate(evt) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
var regex = /^[0-9a-zA-Z\s\b]+$/;
if (!regex.test(key)) {
theEvent.returnValue = false;
if (theEvent.preventDefault)
theEvent.preventDefault();
}
}
<asp:TextBox ID="txtVal" runat="server" onKeyPress="validate(e);"></asp:TextBox>
var re = /^-?\d+$/;
var matches = re.test(args.Value);
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
Blog that contains articles about new technologies related or not with programming. I will describe and solves some problems that I encounter in my career. ASP .NET, AJAX, Javascript, C++, C# and SQL are some of the subjects that will appear.
26 April 2016
Allow only alphanumeric in textbox using javascript and regular expression
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment