Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Don't Accept the number that start with zero using jquery validation

I’m trying to validate the input field, that shouldn’t accept the numbers leading with zero like
0001,01,000001,0000045….

jQuery.validator.addMethod("numberNotStartWithZero", function(value, element) { 
return this.optional(element) || /^[1-9][0-9]+$/i.test(value); 
}, "Please enter a valid number. (Do not start with zero)");

I found this above code and tried, Validation is working fine.
But it’s not accepting single digit values ( 1 -9 ). Accepting from 10 only.

Anyone can help me to fix this issue. Thanks in Advance

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

[1-9][0-9] is two digits

try

/^[1-9][0-9]*$/

https://regex101.com/r/5lWQa3/2

* is 0 or more of the preceding

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading