troubleshooting Question

JQuery Custom Validator in ASP.NET Form

Avatar of XGIS
XGISFlag for Australia asked on
ASP.NETJavaScriptC#jQuery
8 Comments1 Solution529 ViewsLast Modified:
I have a snippet of JQuery I need to get running in an ASPX page. It is a custom validator of a number entered into a textbox.

Ideally the script would make a button active and display text on the button. eg Number Valid (button is active) else Number Invalid (Button Inactive).  I would like to do this without C# as I am trying to move away from server side dependency.

I would like to run this as a piece of script in the head/form but have no worries about it being a seperate script.js.
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'
);

Open in new window

ASKER CERTIFIED SOLUTION
adilet_nasirdinov

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros