We help IT Professionals succeed at work.
Get Started

JQuery Custom Validator in ASP.NET Form

XGIS asked
Last Modified: 2012-05-11
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.
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

Watch Question
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE