Skip to content

Instantly share code, notes, and snippets.

@Alex1990
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save Alex1990/1dc0178b355ccea04bca to your computer and use it in GitHub Desktop.

Select an option

Save Alex1990/1dc0178b355ccea04bca to your computer and use it in GitHub Desktop.
Decimal number regular expression.
/**
* Decimal number regular expression.
*
* Valid decimal strings:
* ['1', '1.', '1.1', '.1', '+1', '+1.', '+1.1', '+.1', '-1', '-1.', '-1.1', '-.1']
* Invalid decimal strings:
* ['', '.', '+.', '-.', '1.1.', '1..1', 'Infinity', '-Infinity']
*
* Ref:
* http://stackoverflow.com/questions/12117024/decimal-number-regular-expression
*/
var rDecimal = /^[+-]?(?:\d+\.?\d*|\.\d+)$/;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment