title: Format expiry date on a credit card in React Native
body: <p>How can I format a text input to <code>MM/YY</code> in React Native?</p>
  
  <p>I have made an onChange function</p>
  
  <pre><code>handleExpiry(expiry) {
    if (expiry.length &gt;= 2) {
      expiry = expiry.substr(0, 2) + '/' + (expiry.substr(3) || '')
    }
  
    this.setState({
      expiry
    })
  }
  </code></pre>
  
  <p>but it lets me write <code>DD/</code> because <code>expiry.substr(3)</code> is always null.</p>
  
  <ul>
  <li><p>I want to strip non-numeric characters. I guess it's done with
  <code>expiry.replace(/[^0-9]/g, '')</code>.</p></li>
  <li><p>I want to make sure the string is only 5 characters, which is <code>expiry.length &lt;= 5</code></p></li>
  <li><p>I want to make sure that the first two characters are less than or
  equal 12, so it might be with <code>parseInt(expiry.substr(0, 2), 10) &gt; 0
  &amp;&amp; parseInt(expiry.substr(0, 2), 10) &lt;= 12</code>.</p></li>
  <li><p>I want to make sure that the third character is '/', which might be with <code>expiry.charAt(2) === '/'</code></p></li>
  <li><p>And finally, I want to make sure that the remaining 2 characters are greater than 17, so it is <code>parseInt(expiry.substr(3), 10) &gt;= 17</code>.</p></li>
  </ul>
  
  <p>But I don't know how to bind it together.</p>