Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Using Regular Expressions to validate a numerical string. (See related posts)

Using Ruby and Regular Expressions, this code validates a string for numbers only. If the string variable contains only numbers then 0 will be returned otherwise nil.

a = '134323'
/^[0-9]*$/ =~ a
#result returns 0, indicating success

You need to create an account or log in to post comments to this site.


Click here to browse all 5140 code snippets

Related Posts