Skip to content

Instantly share code, notes, and snippets.

@narainsagar
Last active October 28, 2016 09:48
Show Gist options
  • Save narainsagar/751f181c769dd9e5b3d2640d0efd6a0b to your computer and use it in GitHub Desktop.
Save narainsagar/751f181c769dd9e5b3d2640d0efd6a0b to your computer and use it in GitHub Desktop.
Sample Regular Expressions

Whole Numbers

Regex to validate all whole numbers only i..e, [0, 1, 2, 3, ....].

(0|[1-9][0-9]*)

Natural Numbers

Regex to validate all natural (psoitive whole) numbers i..e, [1, 2, 3, ....] sometimes 0 as well.

including zero (0): (0|[1-9][0-9]*)

excluding zero (0): ([1-9][0-9]*)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment