Perl validating numbers
@list = qw(5 4.4 0 -1.2 asdf 12asdf asdf12 1.2e3 0e0); foreach $thing (@list) Note that ("12asdf" * 1) equals 12...
Also note that the above example does NOT work for numbers in scientific notation.
# zero or one letter \s* # optional trailing whitespace (just in case) $ # end of string Actually, NIN doesn't allow D, F, I, Q, U or V for the first two letters and doesn't allow O for the second letter; on top of this, the prefix letters can not be BG, GB, NK, KN, TN, NT and ZZ.
Also the suffix letter is either A, B, C or D, but may be represented by a space if unknown.
For something as fundamental as this it really should be.
Also, you may want to check out the other posts in the series.
The comments in the code will make more sense if you have seen the other examples. /usr/bin/perl # Functions in Perl are called subroutines.
Edit: Andrew Bauer modified my answer to add checks for allowed/disallowed characters that were unknown at the time I answered.
You should up-vote his answer since it is more complete and apparently performs better validation.