View the Project on GitHub on-site/guards.js


Numerical guards

Some guards can take options which affect how the guard behaves. The "int", "float", and "moneyUS" guards can have min, max or min and max options which determine the acceptable range of those inputs. Note that these numeric guards (along with most guards) will pass if no input is provided. You must use the required guard along with them if you want no input to cause an error. There is no problem using multiple guards against a single field. Try out the numeric guards in the forms below:


minimum 5

maximum 15

minimum -5, maximum 42


minimum -5.3

maximum 42.42

minimum 0, maximum 0.999


minimum -$0.42

maximum $50.50

minimum $15, maximum $50


The "string" guard can be used to validate the length of the user's provided input. This checks the length against the provided min and/or max options. This behaves different from most other guards besides "required" in that empty input can trigger an error. Whitespace at the beginning or end of the input is ignored with respect to the validated length. Try out the guard below:


minimum length 2

maximum length 5

minimum length 2, maximum length 4

Allow and disallow

If you need to block all input except a few specific values, the "allow" guard is for you! You can list a bunch of inputs, and the guard will fail unless the input matches one of the values. If you need the opposite, and want to block specific inputs, then use the "disallow" guard. Try it out below:


a color


not a color

previous next