Step 1:- JavaScript Code
<script type="text/javascript">
function UpperCase(ctrlID)
{
var PANNo
= document.getElementById(ctrlID).value;
if (PANNo
!= "") {
document.getElementById(ctrlID).value
= PANNo.toUpperCase();
}
}
function ValidatePAN(ctrlID)
{
var PANNo
= document.getElementById(ctrlID).value;
if (PANNo.value
!= "") {
var ObjVal
= PANNo;
var panPattern
= /^([a-zA-Z]{5})(\d{4})([a-zA-Z]{1})$/;
var matchArray
= ObjVal.match(panPattern);
if (matchArray
== null) {
alert('Invalid
PAN Card No.');
return false;
}
return true;
}
}
</script>
Step 2:- Design Page
<table style="border: 1px; width: 500px;">
<tr>
<td style="width: 200px;">
<label for="panno">PAN No:</label>
</td>
<td style="width: 200px;">
<asp:TextBox ID="panno" runat="server" placeholder="Enter
PAN No" ClientIDMode="Static" onkeypress="UpperCase('panno');" onkeyup="UpperCase('panno');" onchange="return
ValidatePAN('panno')"></asp:TextBox>
</td>
</tr>
</table>
Step 3:- Complete Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Demo.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Validate
PAN Card Number</title>
<script type="text/javascript">
function UpperCase(ctrlID)
{
var PANNo
= document.getElementById(ctrlID).value;
if (PANNo
!= "") {
document.getElementById(ctrlID).value
= PANNo.toUpperCase();
}
}
function ValidatePAN(ctrlID)
{
var PANNo
= document.getElementById(ctrlID).value;
if (PANNo.value
!= "") {
var ObjVal
= PANNo;
var panPattern
= /^([a-zA-Z]{5})(\d{4})([a-zA-Z]{1})$/;
var matchArray
= ObjVal.match(panPattern);
if (matchArray
== null) {
alert('Invalid
PAN Card No.');
return false;
}
return true;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="border: 1px; width: 500px;">
<tr>
<td style="width: 200px;">
<label for="panno">PAN No:</label>
</td>
<td style="width: 200px;">
<asp:TextBox ID="panno" runat="server" placeholder="Enter
PAN No" ClientIDMode="Static" onkeypress="UpperCase('panno');" onkeyup="UpperCase('panno');" onchange="return
ValidatePAN('panno')"></asp:TextBox>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
No comments:
Post a Comment