Android Code Snippet Find Numbers RegEx Expressions

Discussion in 'Code Snippets' started by icakinser, May 11, 2019.

  1. icakinser

    icakinser Member Licensed User

    Here is a list of expressions to use with RegEx:
    Positive Integers:

    ^\d+$
    Negative Integers:

    ^-\d+$
    Integer:

    ^-?\d+$
    Positive Number:

    ^\d*\.?\d+$
    Negative Number:

    ^-\d*\.?\d+$
    Positive Number or Negative Number:

    ^-?\d*\.{0,1}\d+$
    Phone number:

    ^\+?[\d\s]{3,}$
    Phone with code:

    ^\+?[\d\s]+\(?[\d\s]{10,}$
    Year 1900-2099:

    ^(19|20)[\d]{2,2}$
    Date (dd mm yyyy, d/m/yyyy, etc.):

    ^([1-9]|0[1-9]|[12][0-9]|3[01])\D([1-9]|0[1-9]|1[012])\D(19[0-9][0-9]|20[0-9][0-9])$
    IP v4:

    ^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]){3}$
     
    DavideV, peacemaker, Erel and 4 others like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice