I have used an expression for validating a positive number as follows:
^\d*\.{0,1}\d+$
when I give it an input of -23, it will mark input as negative, but when I give it an input of +23, it will mark it as invalid number!
what is the problem?
Can anyone give a solution that With +23 it will return (positive)?
As we know, the <input type="number"> specifies a field for entering a number. If you want to restrict the <input> field to only positive numbers, you can use the min attribute.
The jQuery $. isNumeric() method is used to check whether the entered number is numeric or not. $. isNumeric() method: It is used to check whether the given argument is a numeric value or not.
Have you considered to use anything beside regular expressions?
If you are using the jQuery Validation Plugin you could create a custom validation method using the Validator/addMethod function:
$.validator.addMethod('positiveNumber',
function (value) {
return Number(value) > 0;
}, 'Enter a positive number.');
Edit: Since you want only regular expressions, try this one:
^\+?[0-9]*\.?[0-9]+$
Explanation:
^
)\+?
)[0-9]*
)\.?
)[0-9]+
)$
)Or simply use: min: 0.01
.
For example for money
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With