<asp:RegularExpressionValidator Display="Dynamic" ControlToValidate="txtPan"
ID="regConVal" ValidationExpression="^[A-Za-z]{5}[0-9]{4}[A-Za-z]{1}$" runat="server" ErrorMessage="PAN Number Should be this format 'XXXXX0000X'."
ForeColor="#ff0000" ValidationGroup="ConVal"></asp:RegularExpressionValidator>
在javascript中
var pan = "ABCDE1234F";
var pan2 = "ASW4578W32"
var patt =/^[A-Za-z]{5}[0-9]{4}[A-Za-z]{1}$/;
console.log(patt.test(pan));
console.log(patt.test(pan2));
或在C#中
using System.Text.RegularExpressions;
string checkPanNo = @"^[A-Za-z]{5}[0-9]{4}[A-Za-z]{1}$";
bool isPANValid = Regex.IsMatch(txtPanNo.Text.ToString().Trim(), checkPanNo);
if (isPANValid == true)
{
//valid pan number
}
else
{
//invalid pan number
}
2条答案
按热度按时间x8diyxa71#
使用
RegularExpressionValidator
来实现尝试这个...在javascript中
或在C#中
l0oc07j22#