Link to home
Start Free TrialLog in
Avatar of Quack
QuackFlag for United States of America

asked on

I have a form field that needs to allow commas for the input but also be in the N.NN Format...see code below...

Here's the code I'm using:

				jQuery.validator.addMethod(
		"money",
			function(value, element) {
				var isValidMoney = /^(\d+|\d{1,3}(,\d{3})*)(\.\d{2})?$/.test(value);
				if(isValidMoney) {
					var testValue = value;
					testValue = testValue.replace(",","",-1);
					if(testValue <= 0){
						isValidMoney = false;
					}
				}
				return this.optional(element) || isValidMoney;
			},
			"Insert"
		);

Open in new window


			}
			, Invoice_Amount: {
				  required: true
				, money: true
				, pattern: /^\d+\.\d{0,2}$/
				, min: .01
			}

Open in new window


Won't catch where I need it to. Anyone see where this would be failing?
Avatar of Coast Line
Coast Line
Flag of Canada image

can you create a jsfiddle for it, easier to debug and make a change
Avatar of Quack

ASKER

not sure what a jsfiddle is :-(
ASKER CERTIFIED SOLUTION
Avatar of Coast Line
Coast Line
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Quack

ASKER

thanks