Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I have tried a regex-pattern that should accept only numbers and NA but I cannot arrive at a solution.Any guidance on this will be of great help
Posted
Comments
Zoltán Zörgő 25-May-13 15:13pm    
What have you tried?
Since regular expressions check syntax, first define the number format you want to accept!
These are all numbers: 1514, -54, 5.6244435243645, -948.32, 0x1A (hexa), 0401 (octal), 0111101 (binary), -5.4e+65 (exponential format)...

1 solution

Please, read Zoltan's Zorgo comment.

The simplest regex pattern is: \d+|(NA).
where:
\d+ - any digit [0-9] (one or more matches)
| alternative (or)
(NA) - "NA"

Please, have a look here: http://www.regular-expressions.info/reference.html[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900