0

Trying to make the value validate as integer and is it possible to make it validate as decimal ? As 23,34 (two in front and two after comma)..

jsfiddle:

http://jsfiddle.net/5WMff/320/

1 Answer 1

1

You can use jQuery.validator.addMethod() method for this:

$.validator.addMethod('decimal', function(value, element) {
return this.optional(element) || /^\d+(\,\d{2,2})?$/.test(value); 
}, "Wrong number format, please enter xx.xx value");

FIDDLE

Sign up to request clarification or add additional context in comments.

3 Comments

That fiddle link goes to my fiddle. You have to update it to generate another link.
If I only want it to validate a integer or decimal. How would the method be for those two ? Because the method described is able to use both integer and decimal.
for integers only you use this regex: /^\d+$/ and for decimals only this one : /^[0-9]*\,[0-9]{2}$/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.