JavaScript Funtion for Validation textbox on onkypress
<script language="javascript" type="text/javascript">
function isCurrency(evt, txtid) {
var charCode = (evt.which) ? evt.which : event.keyCode
var ctrl = document.getElementById(txtid)
if (ctrl.value.indexOf('.') == -1 && charCode == 46)
true;
else if (charCode > 31 && (charCode < 48 || charCode > 57)) {
alert(" you can enter Only Numeric character..!!!");
return false;
}
return true;
}
function CheckDate(sender, args) {
if (sender._selectedDate > new Date()) {
alert("Please Select Valid Birth Date...!!");
sender._selectedDate = new Date();
sender._textbox.set_Value(sender._selectedDate.format(sender._format));
}
}
function OnlyAlphabets(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if ((charCode >= 97 && charCode <= 122) || (charCode >= 65 && charCode <= 90) || (charCode <= 32))
true;
else {
alert("Only Alhaphet Characters Are Allowed To Enter..!!!");
return false;
}
return true;
}
function DisableButton(buttonElem) {
buttonElem.value = "Please Wait....";
buttonElem.disabled = true;
}
function isName(evt, txtid) {
var charCode = (evt.which) ? evt.which : event.keyCode
var ctrl = document.getElementById(txtid)
if ((charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) || (charCode == 32) || (charCode == 46)) {
return true;
}
else
alert("You Can Enter Only Alphabets,Space,Or Dot(.)");
return false;
}
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
alert("you can enter Only Numeric character..!!!");
return false;
}
return true;
}
function isPhoneNo(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode == 45) return true;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
alert("you can enter Only Numeric characters and '-' ...!!!");
return false;
}
return true;
}
function NoNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode >= 48 && charCode <= 57) {
alert("Digits are not allowed..!!!");
return false;
}
return true;
}
</script>
function isCurrency(evt, txtid) {
var charCode = (evt.which) ? evt.which : event.keyCode
var ctrl = document.getElementById(txtid)
if (ctrl.value.indexOf('.') == -1 && charCode == 46)
true;
else if (charCode > 31 && (charCode < 48 || charCode > 57)) {
alert(" you can enter Only Numeric character..!!!");
return false;
}
return true;
}
function CheckDate(sender, args) {
if (sender._selectedDate > new Date()) {
alert("Please Select Valid Birth Date...!!");
sender._selectedDate = new Date();
sender._textbox.set_Value(sender._selectedDate.format(sender._format));
}
}
function OnlyAlphabets(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if ((charCode >= 97 && charCode <= 122) || (charCode >= 65 && charCode <= 90) || (charCode <= 32))
true;
else {
alert("Only Alhaphet Characters Are Allowed To Enter..!!!");
return false;
}
return true;
}
function DisableButton(buttonElem) {
buttonElem.value = "Please Wait....";
buttonElem.disabled = true;
}
function isName(evt, txtid) {
var charCode = (evt.which) ? evt.which : event.keyCode
var ctrl = document.getElementById(txtid)
if ((charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) || (charCode == 32) || (charCode == 46)) {
return true;
}
else
alert("You Can Enter Only Alphabets,Space,Or Dot(.)");
return false;
}
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
alert("you can enter Only Numeric character..!!!");
return false;
}
return true;
}
function isPhoneNo(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode == 45) return true;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
alert("you can enter Only Numeric characters and '-' ...!!!");
return false;
}
return true;
}
function NoNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode >= 48 && charCode <= 57) {
alert("Digits are not allowed..!!!");
return false;
}
return true;
}
</script>
example
<html>
<head>
</head>
<body>
<table>
<tr>
<td>
<asp:TextBox ID="txtBpin" runat="server" CssClass="txt" Height="18px" onkeypress="return isNumberKey(event);"
Width="128px" MaxLength="6" />
</td>
<td>
<asp:TextBox ID="txtBfax" runat="server" onkeypress="return isPhoneNo(event);" CssClass="txt"
MaxLength="10" Height="18px" Width="128px" />
</td>
<td align="left">
<asp:TextBox ID="txtTotalCost" runat="server" CssClass="txt" Enabled="False" Height="18px"
onkeypress="return isCurrency(event,this.id);" Width="116px" />
</td>
</tr>
</table>
</body>
</html>
<head>
</head>
<body>
<table>
<tr>
<td>
<asp:TextBox ID="txtBpin" runat="server" CssClass="txt" Height="18px" onkeypress="return isNumberKey(event);"
Width="128px" MaxLength="6" />
</td>
<td>
<asp:TextBox ID="txtBfax" runat="server" onkeypress="return isPhoneNo(event);" CssClass="txt"
MaxLength="10" Height="18px" Width="128px" />
</td>
<td align="left">
<asp:TextBox ID="txtTotalCost" runat="server" CssClass="txt" Enabled="False" Height="18px"
onkeypress="return isCurrency(event,this.id);" Width="116px" />
</td>
</tr>
</table>
</body>
</html>