Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

test field for numeric or alpha-numeric 2

Status
Not open for further replies.

rufflocks

Technical User
Jun 29, 2001
26
US
The record is pipe-delimited.
I want to check if a field is numeric or alpha-numeric.
something like: if ($2 is numeric) { do something; }

Any suggestions?
 
if ($2 ~ /^[0-9][0-9]*$/) { doNumeric }

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thank you.

Tell me, though, why is it necessary to have two [0-9]'s?
I tried the script as: &quot;if ($2 ~ /^[0-9]*$/) {doNumeric }&quot; and it seems to give the results I want.
 
A single [0-9] will work OK, but it will also match a blank field - the * means 0 or more occurrences of the expression. By using [0-9][0-9] we are ensuring we have at least 1 occurrence of a digit.

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top