Jump to content
Cobra23

jQuery way to block/trim more than one zeros

Recommended Posts

Posted (edited)

Hi,

Is there a jQuery validator way to block two or more 0's input and allow one 0. Or even trim the inputs like 00 or 000 or 0000 or 00000 etc and replace it with 0. But I also, want to allow all 0's after a positive number.

I can do it on server side no problem but in the jQuery validator i am struggling to do this.

Thanks

Edited by Cobra23

Share this post


Link to post
Share on other sites

Don't allow multiple consecutive zeros, or do but reduce them, but do allow multiple consecutive zeros after a number? What?

What are some examples of good and of bad values, and what makes them good or bad?

Share this post


Link to post
Share on other sites

Yes, not to allow multiple zeros in one input box without another positive digit. It is a case of the client validation notifying the user of their input being wrong eg bootstraps red highlighted input boxes that notifies the user of the input being wrong and needs to be sorted. Inputs of two or more 0's only should not be allowed in this case.

Anyways, I got this sorted with the following regex.

/^([0]|[1-9]|[1-9][0-9]+)$/

 

Share this post


Link to post
Share on other sites
Posted (edited)

So what you meant is that you want to validate a positive integer without leading zeroes? Then yes, that will do it; my answer would have been

/^(0|[1-9]\d*)$/

but that's basically the same thing.

Edited by requinix

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.