jQuery.validator.addMethod(
'abn',
function(value, element) {
if (!value.length && this.optional(element))
return true;
if (value.length != 11 || isNaN(parseInt(value)))
return false;
var weighting = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
var tally = (parseInt(value.charAt(0)) – 1) * weighting[0];
for (var i = 1; i < value.length; i++) {
tally += (parseInt(value.charAt(i)) * weighting[i]);
}
return (tally % 89) == 0;
}, 'This ABN is not valid'
);
ASKER
ASKER
<head runat="server">
<title></title>
<script src="App_Scripts/jquery-1.6.1.js" type="text/javascript"></script>
<script type="text/javascript">
function ABNValidator(value, element)
{
element.IsValid = false;
$(".txtABN").each(function ()
{
if (!value.length && this.optional(element))
return true;
if (value.length != 11 || isNaN(parseInt(value)))
return false;
var weighting = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
var tally = (parseInt(value.charAt(0)) – 1) * weighting[0];
for (var i = 1; i < value.length; i++)
{
tally += (parseInt(value.charAt(i)) * weighting[i]);
}
return (tally % 89) == 0;
{
element.IsValid = true;
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Australian Business Number : "></asp:Label>
<asp:TextBox ID="TextBox1" TextMode="SingleLine" runat="server" CssClass='txtABN'
MaxLength="11" />
<br />
<asp:CustomValidator ID="CustomValidator1" runat="server" Display="Dynamic" ErrorMessage="Field cannot be blank<br/>Minimum 11, Maximum 11 chars allowed<br/>"
ClientValidationFunction="ABNValidator" OnServerValidate="CustomValidator1_ServerValidate">
</asp:CustomValidator>
<br />
<asp:Button ID="Button1" runat="server" Text="Validate ABN" />
</div>
</form>
</body>
</html>
ASKER
ASKER
ASKER
The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications
TRUSTED BY
http://stackoverflow.com/questions/459871/elegant-way-to-combine-asp-net-validation-with-jquery