Created
November 22, 2019 09:21
-
-
Save VasylShevchenko/aac5b9fd3a3a88c313499006d1622e45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://medium.com/launch-school/number-validation-with-regex-ruby-393954e46797 | |
def number?(obj) | |
obj = obj.to_s unless obj.is_a? String | |
/\A[+-]?\d+(\.[\d]+)?\z/.match(obj) | |
end | |
/\A[+-]?\d+(\.\d+)?\z/ | |
/ start of the regex | |
\A start of the string to be matched | |
[+-]? zero or one of '+' or'-' | |
\d+ one or more of digit | |
(\.\d+)? zero or one of 'one dot and 'one or more of digit'' | |
\z end of the string to be matched | |
/ end of the regex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment