Only Number allowed using Javascript
function onlyNumbers(evt) {
var charCode;
if (window.event)
charCode = window.event.keyCode; //if IE
else
charCode = evt.which; //if firefox
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
alert("Please Enter Only Numeric Value");
return false;
}
return true;
}
function ValidateText(i) {
if (i.value.length > 0) {
i.value = i.value.replace(/[^\d]+/g, '');
}
}
Call :-
<asp:TextBox ID="txtSoWValue" runat="server" onkeyup="javascript:ValidateText(this)" onkeypress="return onlyNumbers(event);" CssClass="left" Style="width: 28%;"></asp:TextBox>
Only Number and Character and space also allowed using Javascript
function ValidateText(i) {
if (i.value.length > 0) {
i.value = i.value.replace(/[!@#$%^&<>?:;|,/]/g, "");
}
}
Only Number and Character allowed using Javascript
function ValidateText(i) {
if (i.value.length > 0) {
i.value = i.value.replace(/[^A-Z0-9]+/ig, '');
}
}
Call :-
<asp:TextBox ID="txtWBSID" runat="server" MaxLength="25" onkeyup="javascript:ValidateText(this)" ></asp:TextBox>
Check the length of character
function CheckTextLength(text, long) {
var maxlength = new Number(long); // Change number to your max length.
if (text.value.length > maxlength) {
text.value = text.value.substring(0, maxlength);
alert(" Only " + long + " Characters Allowed");
}
}
Call :-
<asp:TextBox ID="txtFinanceRemarks" runat="server" TextMode="MultiLine" Width="900px" placeholder="Maximum 500 Characters" onKeyUp="CheckTextLength(this,500)" onChange="CheckTextLength(this,500)" ></asp:TextBox>
onChange="CheckTextLength(this,500)"
function onlyNumbers(evt) {
var charCode;
if (window.event)
charCode = window.event.keyCode; //if IE
else
charCode = evt.which; //if firefox
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
alert("Please Enter Only Numeric Value");
return false;
}
return true;
}
if (i.value.length > 0) {
i.value = i.value.replace(/[^\d]+/g, '');
}
}
Call :-
<asp:TextBox ID="txtSoWValue" runat="server" onkeyup="javascript:ValidateText(this)" onkeypress="return onlyNumbers(event);" CssClass="left" Style="width: 28%;"></asp:TextBox>
Only Number and Character and space also allowed using Javascript
function ValidateText(i) {
if (i.value.length > 0) {
i.value = i.value.replace(/[!@#$%^&<>?:;|,/]/g, "");
}
}
Only Number and Character allowed using Javascript
function ValidateText(i) {
if (i.value.length > 0) {
i.value = i.value.replace(/[^A-Z0-9]+/ig, '');
}
}
Call :-
<asp:TextBox ID="txtWBSID" runat="server" MaxLength="25" onkeyup="javascript:ValidateText(this)" ></asp:TextBox>
Check the length of character
function CheckTextLength(text, long) {
var maxlength = new Number(long); // Change number to your max length.
if (text.value.length > maxlength) {
text.value = text.value.substring(0, maxlength);
alert(" Only " + long + " Characters Allowed");
}
}
Call :-
<asp:TextBox ID="txtFinanceRemarks" runat="server" TextMode="MultiLine" Width="900px" placeholder="Maximum 500 Characters" onKeyUp="CheckTextLength(this,500)" onChange="CheckTextLength(this,500)" ></asp:TextBox>
onChange="CheckTextLength(this,500)"