Alpha numeric characters
does anyone know of an easy technique to test whether or not characters in a field are numeric?
Would that not be just to check that after it's been filtered (for '0123456789') that the length of the original field is the same as the length of the filtered field? That is:
If (Length (Filter (<text field name>; "0123456789" ) = Length (<text field name>); "Yes"; "No" )
Thank you for your post.
Assuming the field is a Text field, you can create a calculation field that returns "Yes" if numeric characters exist, or "No" if numeric characters don't exist. There are a few ways to accomplish this, but this is one of the easier calculations to understand:
If (PatternCount (field, "0" ) or PatternCount (field, "1" ) or PatternCount (field, "2" ) or PatternCount (field, "3" ) or PatternCount (field, "4" ) or PatternCount (field, "5" ) or PatternCount (field, "6" ) or PatternCount (field, "7" ) or PatternCount (field, "8" ) or PatternCount (field, "9" ); "Yes"; "No" )
The PatternCount function returns the number of occurrences a text string appears in another string. In this case, the text string is a number. Therefore, this calculation checks to see if a "0" exists in the field. If so, a positive value is returned. If not, the value is 0. We check for all 10 digits (0 through 9). If one of these values has a positive value, then "Yes" is returned. Otherwise, no numbers exist in the field and we return "No".
Let me know if you have any questions.
Another method would be a calculation that measured the length of the field after you Filter it for the values: "1234567890". You would get "0" if it contained NO numeric values, and a larger value if it did contain them.
The answer provided by sHuston is a more efficient method (Thank you!). To expand on it...
The Filter function has two parts; the first part which is a text string or text field, and the second part contains the characters you want to filter from the first part. For example:
Filter ("800-555-1212"; "0123456789" ) returns 8005551212.
That is, it filters only those characters from the second part that exist in the first part. All other characters are ignored. In the above case, the hyphens are dropped because they do not exist in the second part.
Using our example,
Filter (<text field name>; "0123456789" ) would return a blank/empty string if no numbers exist in the field. If numbers did exist, they would be filtered shown in the resulting string.
Next, take the length of the Filter. If the string is blank/empty (no numbers), the result is 0. Otherwise, the value returned is the length of the string. Putting this all together, the final calculation would be:
If (Length (Filter (<text field name>; "0123456789" ); "Yes"; "No" )
This may not be as easy to understand, but it accomplishes the same thing as the first calculation.
Thanks for all the good ideas.
Now, how can we test that ALL characters in a text field are numeric?
Thank you again.
Retrieving data ...