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

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Using Regular Expressions to validate a fixed length numerical string.

Using Ruby and Regular Sxpressions, this code successfully validates a string if it contains exactly 3 numbers.

a = '547'
/^\d\d\d$/ ~= a

Using Regular Expressions to validate a numerical string.

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
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS